[Python] numpy.ndarray.shape

ndarray.shape

Tuple of array dimensions.

 

x = np.array([1, 2, 3, 4])
print x.shape
#(4, )

y = np.zeros((2, 3, 4))
y.shape
#(2, 3, 4)
y.shape = (3, 8)
y
#array([[ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
#       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
#       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.]])
y.shape = (3, 6)
#Traceback (most recent call last):
#  File "<stdin>", line 1, in <module>
#ValueError: total size of new array must be unchanged

  

posted @ 2017-03-23 22:20  KennyRom  阅读(798)  评论(0编辑  收藏  举报