numpy学习2
2.2 The Basics
NumPy’s main object is the homogeneous multidimensional array. It is a table of elements (usually numbers), all of the same type, indexed by a tuple of non-negative integers. In NumPy dimensions are called axes
NumPy的主要对象是同类型的多维数组。它是所有相同类型的元素(通常为数字)表,由非负整数元组索引。在NumPy中,维度称为轴
For example, the coordinates of a point in 3D space [1, 2, 1] has one axis. That axis has 3 elements in it, so we say it has a length of 3. In the example pictured below,the array has 2 axes. The first axis has a length of 2,the second axis has a length of 3.
例如,三维空间[1,2,1]中的点的坐标有一个轴。这个轴有3个元素,所以我们说这个轴的长度为3。在下面的例子中,数组有两个轴。第一个轴的长度是2,第二个轴的长度是3。
[[ 1., 0., 0.], [ 0., 1., 2.]]
NumPy’s array class is called ndarray. It is also known by the alias array. Note that numpy.array is not the same as the Standard Python Library class array.array, which only handles one-dimensional arrays and offers less functionality. The more important attributes of an ndarray object are:
Numpy的数组类被称为ndarray. ndarray也叫别名数组。注意numpy.array与标准库中array.array不一样,array.array仅仅是一维数组,并且提供更少的功能。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
数组的维数。这是一个整数元组,表示每个维度中数组的大小。对于一个有n行和m列的矩阵,形状将是(n,m)。形状元组的长度因此是轴数ndim,这里ndim为2。
ndarray.size: the total number of elements of the array. This is equal to the product of the elements of shape
数组元素的总数。它等于形状元素的乘积