shape这个我看一次忘记一次,金鱼脑本脑了!!!
二维情况:
>>> a = np.array([[2,3,33],[2,1,1]])
>>> a
array([[ 2, 3, 33],
[ 2, 1, 1]])
>>> a.shape[0]
2
>>> a.shape[1]
3
>>> a.shape[2]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
多维情况:(自外向里解包)
一个一阶的张量[1,2,3]的shape是(3,); 一个二阶的张量[[1,2,3],[4,5,6]]的shape是(2,3);一个三阶的张量[[[1],[2],[3]],[[4],[5],[6]]]的shape是(2,3,1)。
numpy.
reshape
(a,newshape,order ='C' )
为数组提供新形状而不更改其数据。