This function is used to create an array by using the existing data in the form of lists, or tuples. This function is useful in the scenario where we need to convert a python sequence into the numpy array object.
numpy.asarray(sequence, dtype = None, order = None)
It accepts the following parameters.
An array with the equivalent values to the sequence is returned.
import numpy as np l=[1,2,3,4,5,6,7] a = np.asarray(l); print(type(a)) print(a)
Output:
import numpy as np l=(1,2,3,4,5,6,7) a = np.asarray(l); print(type(a)) print(a)
Output:
import numpy as np l=[[1,2,3,4,5,6,7],[8,9]] a = np.asarray(l); print(type(a)) print(a)
Output: