You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.8 KiB
82 lines
2.8 KiB
array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
|
|
|
|
Create an array.
|
|
|
|
:param object: An array, any object exposing the array interface, an
|
|
object whose __array__ method returns an array, or any
|
|
(nested) sequence.
|
|
:type object: array_like
|
|
:param dtype: 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.
|
|
:type dtype: data-type, optional
|
|
:param copy: 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.).
|
|
:type copy: bool, optional
|
|
:param order: Specify the order of the array. If order is 'C', then the array
|
|
will be in C-contiguous order (last-index varies the fastest).
|
|
If order is 'F', then the returned array will be in
|
|
Fortran-contiguous order (first-index varies the fastest).
|
|
If order is 'A' (default), then the returned array may be
|
|
in any order (either C-, Fortran-contiguous, or even discontiguous),
|
|
unless a copy is required, in which case it will be C-contiguous.
|
|
:type order: {'C', 'F', 'A'}, optional
|
|
:param subok: If True, then sub-classes will be passed-through, otherwise
|
|
the returned array will be forced to be a base-class array (default).
|
|
:type subok: bool, optional
|
|
:param ndmin: 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.
|
|
:type ndmin: int, optional
|
|
|
|
:returns: **out** -- An array object satisfying the specified requirements.
|
|
:rtype: ndarray
|
|
|
|
.. seealso:: :obj:`empty`, :obj:`empty_like`, :obj:`zeros`, :obj:`zeros_like`, :obj:`ones`, :obj:`ones_like`, :obj:`fill`
|
|
|
|
.. rubric:: 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','<i4'),('b','<i4')])
|
|
>>> 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]])
|