《Python数据分析技术栈》第05章 03 获取数组属性(Obtaining the properties of an array)
Array properties like their size, dimensions, number of elements, and memory usage can be found out using attributes.
数组的属性,如大小、尺寸、元素数量和内存使用量,都可以通过属性来查找。
Consider the following array:
请看下面的数组:
x=np.arange(0,10).reshape(5,2)
The size property gives the number of elements in the array.
size 属性给出了数组中元素的个数。
The ndim property gives the number of dimensions.
ndim 属性给出了维数。
The memory (total number of bytes) occupied by an array can be calculated using the nbytes attribute.
可以使用 nbytes 属性计算数组占用的内存(字节总数)。
The data type of elements in this array can be calculated using the dtype attribute.
该数组中元素的数据类型可通过 dtype 属性计算得出。
Note the difference between the dtype and the type of an array. The type function gives the type of the container object (in this case, the type is ndarray), and dtype, which is an attribute, gives the type of individual items in the array.
请注意 dtype 与数组类型之间的区别。type 函数给出了容器对象的类型(在本例中,类型是ndarray),而作为属性的 dtype 则给出了数组中各个项的类型。