numpy.array() in PythonThe 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 onedimensional arrays and provides less functionality. SyntaxParametersThere are the following parameters in numpy.array() function. 1) object: array_like Any object, which exposes an array interface whose __array__ method returns any nested sequence or an array.2) dtype : optional datatype This parameter is used to define the desired parameter for the array element. If we do not define the data type, then it will determine the type as the minimum type which will require to hold the object in the sequence. This parameter is used only for upcasting the array.3) copy: bool(optional) If we set copy equals to true, the object is copied else the copy will be made when an object is a nested sequence, or a copy is needed to satisfy any of the other requirements such as dtype, order, etc.4) order : {'K', 'A', 'C', 'F'}, optional The order parameter specifies the memory layout of the array. When the object is not an array, the newly created array will be in C order (row head or rowmajor) unless 'F' is specified. When F is specified, it will be in Fortran order (column head or columnmajor). When the object is an array, it holds the following 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 subclasses will passthrough; otherwise, the returned array will force to be a baseclass 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. ReturnsThe numpy.array() method returns an ndarray. The ndarray is an array object which satisfies the specified requirements. Example 1: numpy.array()Output: array([1, 2, 3]) In the above code
In the output, an array has been shown. Example 2:Output: array([1., 2., 3.]) 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. Example 3: More than one dimensionsOutput: array([[1., 2., 3.], [4., 5., 7.]]) In the above code
In the output, a multidimensional array has been shown. Example 4: Minimum dimensions: 2Output: array([[1., 2., 3.]]) In the above code
In the output, a twodimensional array has been shown. Example 5: Type providedOutput: array([12.+0.j, 45.+0.j, 3.+0.j]) In the above code
In the output, the values of the 'arr' elements have been shown in the form of complex numbers. Example 6: Creating an array from subclassesOutput: array([[1, 2], [3, 4]]) matrix([[1, 2], [3, 4]]) In the above code
In the output, a multidimensional array has been shown.
Next Topicnumpy.concatenate() in Python
