Movatterモバイル変換


[0]ホーム

URL:


SciPy

numpy.array

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

Create an array.

Parameters:

object : array_like

An array, any object exposing the array interface, an object whose__array__ method returns an array, or any (nested) sequence.

dtype : data-type, optional

The desired data-type for the array. If not given, then the type willbe determined as the minimum type required to hold the objects in thesequence. This argument can only be used to ‘upcast’ the array. Fordowncasting, use the .astype(t) method.

copy : bool, optional

If true (default), then the object is copied. Otherwise, a copy willonly 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.).

order : {‘K’, ‘A’, ‘C’, ‘F’}, optional

Specify the memory layout of the array. If object is not an array, thenewly created array will be in C order (row major) unless ‘F’ isspecified, in which case it will be in Fortran order (column major).If object is an array the following holds.

orderno copycopy=True
‘K’unchangedF & C order preserved, otherwise most similar order
‘A’unchangedF order if input is F and not C, otherwise C order
‘C’C orderC order
‘F’F orderF order

Whencopy=False and a copy is made for other reasons, the result isthe same as ifcopy=True, with some exceptions forA, see theNotes section. The default order is ‘K’.

subok : bool, optional

If True, then sub-classes will be passed-through, otherwisethe returned array will be forced to be a base-class array (default).

ndmin : int, optional

Specifies the minimum number of dimensions that the resultingarray should have. Ones will be pre-pended to the shape asneeded to meet this requirement.

Returns:

out : ndarray

An array object satisfying the specified requirements.

Notes

When order is ‘A’ andobject 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 isnot necessarily ‘C’ as expected. This is likely a bug.

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]])

Previous topic

numpy.full_like

Next topic

numpy.asarray

  • © Copyright 2008-2009, The Scipy community.
  • Last updated on Jun 10, 2017.
  • Created usingSphinx 1.5.3.

[8]ページ先頭

©2009-2025 Movatter.jp