The homogeneous multidimensional array is the main object of NumPy. It is basically a table of elements which are all of the same type and indexed by a tuple of positive integers. The dimensions are called axis in NumPy.
The NumPy's array class is known as ndarray or alias array. The numpy.array is not the same as the standard Python library class array.array. The array.array handles only one-dimensional arrays and provides less functionality.
numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)
There are the following parameters in numpy.array() function.
1) object: array_like
2) dtype : optional data-type
3) copy: bool(optional)
4) order : {'K', 'A', 'C', 'F'}, optional
order | no copy | copy=True |
---|---|---|
'K' | Unchanged | F and C order preserved. |
'A' | Unchanged | When the input is F and not C then F order otherwise C order |
'C' | C order | C order |
'F' | F order | F order |
When copy=False or the copy is made for the other reason, the result will be the same as copy= True with some exceptions for A. The default order is 'K'.
5) subok : bool(optional)
When subok=True, then sub-classes will pass-through; otherwise, the returned array will force to be a base-class array (default).
6) ndmin : int(optional)
This parameter specifies the minimum number of dimensions which the resulting array should have. Users can be prepended to the shape as needed to meet this requirement.
The numpy.array() method returns an ndarray. The ndarray is an array object which satisfies the specified requirements.
import numpy as np arr=np.array([1,2,3]) arr
Output:
In the above code
In the output, an array has been shown.
import numpy as np arr=np.array([1,2.,3.]) arr
Output:
In the above code
In the output, an array has been displayed containing elements in such type which require minimum memory to hold the object in the sequence.
import numpy as np arr=np.array([[1,2.,3.],[4.,5.,7]]) arr
Output:
In the above code
In the output, a multi-dimensional array has been shown.
import numpy as np arr=np.array([1,2.,3.],ndmin=2) arr
Output:
In the above code
In the output, a two-dimensional array has been shown.
import numpy as np arr=np.array([12,45.,3.],dtype=complex) arr
Output:
In the above code
In the output, the values of the 'arr' elements have been shown in the form of complex numbers.
import numpy as np arr=np.array(np.mat('1 2;3 4')) arr arr=np.array(np.mat('1 2;3 4'),subok=True) arr
Output:
In the above code
In the output, a multi-dimensional array has been shown.