kame
kame

Reputation: 21970

Python: shape of a matrix and imshow()

I have a 3-D array ar.

print shape(ar)  # --> (81, 81, 256) 

I want to plot this array.

fig = plt.figure()
ax1 = fig.add_subplot(111)
for i in arange(256):
    im1 = ax1.imshow(ar[:][:][i])
    plt.draw()
    print i

I get this error-message:

    im1 = ax1.imshow(ar[:][:][i])
IndexError: list index out of range

Why do I get this strange message? The graph has the size 81 x 256 and not like expected 81 x 81. But why?

Upvotes: 0

Views: 1928

Answers (1)

Katriel
Katriel

Reputation: 123662

Do:

ar[:,:,i]

The syntax ar[:] makes a copy of ar (slices all its elements), so ar[:][:][i] is semantically equivalent to ar[i]. This is an 81*256 matrix, since ndarrays are nested lists.

Upvotes: 2

Related Questions