numpy.array(object,dtype=None,copy=True,order='K',subok=False,ndmin=0)¶Create an array.
| Parameters: | object : array_like
dtype : data-type, optional
copy : bool, optional
order : {‘K’, ‘A’, ‘C’, ‘F’}, optional
subok : bool, optional
ndmin : int, optional
| |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Returns: | out : ndarray
|
See also
empty,empty_like,zeros,zeros_like,ones,ones_like,full,full_like
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]])