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?
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.
精彩评论