What is the numpy.array() function in Python?
Overview
The numpy.array() function is used to create an
Syntax
numpy.array(object, dtype=None, ndmin=0, like=None)
Parameters
The numpy.array() function takes the following parameter values:
object: This represents thearray_likeobject.dtype: This represents the desired data type of the array to be created. This is optional.ndim: This represents the minimum dimension of the desired array. This is optional.
Return value
The numpy.array() function returns an array object with the specified parameters.
Example
import numpy as np# implementing the numpy.array() functionmyarray = np.array([1, 2, 3, 4, 5,], dtype = complex, ndmin= 2)print(myarray)
Explanation
- Line 1: We import the
numpymodule. - Line 4: Using the
numpy.array()function, we create an array with complex data types that have at least2dimensional values. The output is assigned to another variable,myarray. - Line 6: We print the variable
myarray.