numpy.array

numpy.array

https://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html

numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)

Create an array.

array [əˈreɪ]:n. 数组,阵列,排列,列阵,大批,一系列,衣服 vt. 排列,部署,打扮

1. Parameters

object : array_like
An array, any object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence.
数组,任何暴露数组接口的对象,其 __array__ 方法返回数组的对象或任何 (嵌套的) 序列。

dtype : data-type, optional
The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence. This argument can only be used to upcast the array. For downcasting, use the .astype(t) method.
数组所需的数据类型。如果未给出,则将类型确定为在序列中保存对象所需的最小类型。此参数只能用于 upcast 数组。对于向下转换,请使用 .astype(t) 方法。

copy : bool, optional
If true (default), then the object is copied. Otherwise, a copy will only be made if __array__ returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy any of the other requirements (dtype, order, etc.).
如果为 true (默认值),则复制对象。否则,只有在 __array__ 返回一个副本,obj 是一个嵌套序列,或者需要满足其他任何要求 (dtype, order, etc.) 的副本时,才创建副本。

order : {‘K’, ‘A’, ‘C’, ‘F’}, optional
Specify the memory layout of the array. If object is not an array, the newly created array will be in C order (row major) unless F is specified, in which case it will be in Fortran order (column major). If object is an array the following holds.
指定数组的内存布局。如果 object 不是数组,则除非指定为 F,否则新创建的数组将以 C 顺序 (row major),在这种情况下,它将以 Fortran 顺序 (column major)。如果 object 是一个数组,则以下成立。

order no copy copy=True
‘K’ unchanged F & C order preserved, otherwise most similar order
‘A’ unchanged F order if input is F and not C, otherwise C order
‘C’ C order C order
‘F’ F order F order

When copy=False and a copy is made for other reasons, the result is the same as if copy=True, with some exceptions for A, see the Notes section. The default order is K.
当 copy=False 且由于其他原因进行复制时,结果与 copy=True 相同,但 A 例外,请参见 Notes 部分。默认顺序为 K

subok : bool, optional
If True, then sub-classes will be passed-through, otherwise the returned array will be forced to be a base-class array (default).
如果为 True,则子类将被传递,否则返回的数组将被强制为基类数组 (默认)。

ndmin : int, optional
Specifies the minimum number of dimensions that the resulting array should have. Ones will be pre-pended to the shape as needed to meet this requirement.
指定结果数组应具有的最小维数。可以根据需要预先添加形状。

2. Returns:

out : ndarray
An array object satisfying the specified requirements.

3. Notes

When order is A and object is an array in neither C nor F order, and a copy is forced by a change in dtype, then the order of the result is not necessarily C as expected. This is likely a bug.
当 order 为 A 且对象不是 CF 顺序的数组,并且由于 dtype 的更改而强制执行副本时,结果的顺序不一定就是预期的 C。这可能是一个错误。

4. Examples

>>> np.array([1, 2, 3])
array([1, 2, 3])

Upcasting:

>>> np.array([1, 2, 3.0])
array([ 1.,  2.,  3.])

More than one dimension:

>>> np.array([[1, 2], [3, 4]])
array([[1, 2],
       [3, 4]])

Minimum dimensions 2:

>>> np.array([1, 2, 3], ndmin=2)
array([[1, 2, 3]])

Type provided:

>>> np.array([1, 2, 3], dtype=complex)
array([ 1.+0.j,  2.+0.j,  3.+0.j])

Data-type consisting of more than one element:

>>> x = np.array([(1,2),(3,4)],dtype=[('a','>> x['a']
array([1, 3])

Creating an array from sub-classes:

>>> np.array(np.mat('1 2; 3 4'))
array([[1, 2],
       [3, 4]])
>>>
>>> np.array(np.mat('1 2; 3 4'), subok=True)
matrix([[1, 2],
        [3, 4]])

你可能感兴趣的:(NumPy)