ndim, size, shape的区别

import numpy as np

c=np.array([1,2,3])
d=np.array([[1,2,3],[4,5,6],[7,8,9]])
e=np.array([[[1,2,3],[4,5,6],[7,8,9]]])

c.ndim  # 1 
d.ndim  # 2
e.ndim  # 3

c.shape  # (3,)
d.shape  # (3, 3)
e.shape  # (1, 3, 3)

c.size  # 3
d.size  # 9
e.size  # 9

ndim描述的是维度

shape描述的是矩阵的形状

size描述的是元素的个数

posted @ 2021-12-04 16:08  KYZH  阅读(192)  评论(0编辑  收藏  举报