06-numpy-笔记-shape

shape 是返回 np.mat 的形状的。

1. 作为 mat 的成员变量,a.shape

2. 作为 np 的成员函数,np.shape

>>> import numpy as np
>>> 
>>> a = np.mat([[1,2,3],[4,5,6]])
>>> a
matrix([[1, 2, 3],
        [4, 5, 6]])
>>> a.shape
(2, 3)
>>>
>>> a.shape() # 错误,不可以执行
>>>
>>>
>>> np.shape(a)
(2, 3)
>>> np.shape(a)[0]
2
>>> np.shape(a)[1]
3
>>> np.shape(a)[2] # 错误,越界

  

原文地址:https://www.cnblogs.com/alexYuin/p/8898174.html