[1 basics]Quickstart tutorial -numpy

numpy里面的array是多维的。每个纬度叫做axes,axes的数量叫做rank

eg:

[1, 2, 1]

is an array of rank 1,因为只有一个axis,axis的长度为3.

[[1.,0.,0.],

[0.,1.,2.]]

这个array 的rank为2,(2-dimensional)

NumPy 的array的类名叫做 ndarraynumpy.array 和标准python的类名 array.array 是不一样的,array.array 是一维的, 同时会提供比较少的方法。那么ndarray的一些重要的attibutes如下:
ndarray.ndim

the number of axes (dimensions) of the array. In the Python world, the number of dimensions is referred to as rank.

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 rows and columns, shape will be(n,m). The length of the shape tuple is therefore the rank, or number of dimensions,ndim.

ndarray.size

the total number of elements of the array. This is equal to the product of the elements ofshape.

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 typefloat64hasitemsize8 (=64/8), while one of typecomplex32hasitemsize4 (=32/8). It is equivalent tondarray.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.


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容