Create an array.
An array, any object exposing the array interface, an object whose
__array__ method returns an array, or any (nested) sequence.
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
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.).
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.
F & C order preserved, otherwise most similar order
F order if input is F and not C, otherwise C 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’.
If True, then sub-classes will be passed-through, otherwise
the returned array will be forced to be a base-class array (default).
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.
Reference object to allow the creation of arrays which are not
NumPy arrays. If an array-like passed in as like supports
the __array_function__ protocol, the result will be defined
by it. In this case, it ensures the creation of an array object
compatible with that passed in via this argument.
The like keyword is an experimental feature pending on
acceptance of NEP 35.
New in version 1.20.0.
An array object satisfying the specified requirements.
Return an empty array with shape and type of input.
Return an array of ones with shape and type of input.
Return an array of zeros with shape and type of input.
Return a new array with shape of input filled with value.
Return a new uninitialized array.
Return a new array setting values to one.
Return a new array setting values to zero.
Return a new array of given shape filled with value.
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.
>>> np.array([1, 2, 3])
array([1, 2, 3])
>>> np.array([1, 2, 3.0])
array([ 1., 2., 3.])
More than one dimension:
>>> np.array([[1, 2], [3, 4]])
Minimum dimensions 2:
>>> np.array([1, 2, 3], ndmin=2)
array([[1, 2, 3]])
>>> 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','<i4'),('b','<i4')])
Creating an array from sub-classes:
>>> np.array(np.mat('1 2; 3 4'))
>>> np.array(np.mat('1 2; 3 4'), subok=True)