Python:numpy中shape和reshape的用法

>>> w=np.zeros((5,6))
>>> w
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.],
       [ 0.,  0.,  0.,  0.,  0.,  0.]])

>>> w.shape[0]
5

>>> w.shape[1]
6

w是一个5行6列的矩阵

w.shape[0]返回的是w的行数

w.shape[1]返回的是w的列数

原文地址:https://www.cnblogs.com/Davirain/p/8520143.html