python中的size和shape

size和shape是numpy中的函数.
size()计算矩阵中所有元素的个数;
shape()返回维度值。即

import numpy as np

a = np.array([[1,2,3],[4,5,6],[7,8,9]])
print(np.size(a))
print(np.shape(a))

返回结果为

9
(3, 3)

shape[0]返回行数,shape[1]返回列数

b = a.shape[0]
print(b)

返回

3

注意,当写作

b = a.shape(0

时,会报错

TypeError: 'tuple' object is not callable

猜你喜欢

转载自blog.csdn.net/Peggiehu/article/details/107004480
今日推荐