读书笔记 numpy入门 第2章 数据属性 Posted on 2019-05-19 | Edited on 2019-05-22 | In 数据科学 https://github.com/jakevdp/PythonDataScienceHandbook NumPy数组的属性 ndim 数组的维度 shape 数组每个维度的大小 size 数组的总大小 dtype 数组的数据类型 itemsize 每个数组元素字节的大小 nbytes 数组总字节大小的属性 用例子体会123456789101112131415161718192021222324import numpy as npnp.random.seed(0)x1 = np.random.randint(10, size=6) # 一维数组x2 = np.random.randint(10, size=(3, 4)) # 二维数组x3 = np.random.randint(10, size=(3, 4, 5)) # 三维数组print("x3 ndim: ", x3.ndim)print("x3 shape:", x3.shape)print("x3 size: ", x3.size)>>> x3 ndim: 3>>> x3 shape: (3, 4, 5)>>> x3 size: 60print("dtype:", x3.dtype)>>>dtype: int64print("itemsize:", x3.itemsize, "bytes")print("nbytes:", x3.nbytes, "bytes")>>> itemsize: 8 bytes>>> nbytes: 480 bytes