Numpy的基本概念

来源:https://www.numpy.org/devdocs/user/quickstart.html

:即维度

eg.

  • [1, 2, 1],有一个轴
  • [[ 1, 0, 0],[ 0, 1, 2]] ,有两个轴,第一个个轴的长度是2,第二个轴的长度是3

ndarray:numpy的数组类,也叫数组

常用的ndarray属性有:

ndarray.ndim
the number of axes (dimensions) of the array.

ndarray.shape
the dimensions of the array. This is a tuple of integers indicating the size of the array in each dimension. For a matrix with n rows and m columns, shape will be (n,m). The length of the shape tuple is therefore the number of axes, ndim.

ndarray.size
the total number of elements of the array. This is equal to the product of the elements of shape.

ndarray.dtype
an object describing the type of the elements in the array. One can create or specify dtype’s using standard Python types. Additionally NumPy provides types of its own. numpy.int32, numpy.int16, and numpy.float64 are some examples.

ndarray.itemsize
the size in bytes of each element of the array. For example, an array of elements of type float64 has itemsize 8 (=64/8), while one of type complex32 has itemsize 4 (=32/8). It is equivalent to ndarray.dtype.itemsize.

ndarray.data
the buffer containing the actual elements of the array. Normally, we won’t need to use this attribute because we will access the elements in an array using indexing facilities.

原文地址:https://www.cnblogs.com/144823836yj/p/10764538.html