In Python, the ndarray.tolist()
method is used to return a copy of an array as a nested list.
ndarray.tolist()
The ndarray.tolist()
method takes no parameter value.
The ndarray.tolist()
method returns an object, a list of object, a list of list of object, or the possibly nested list of elements of an array.
import numpy as np# creating an arraymyarray = np.array([1, 2, 3, 4, 5])# implementing the ndarray.tolist() methodmylist = myarray.tolist()print(mylist)# checking for the data typeprint(type(mylist))
numpy
module.numpy.array()
function to create a 1D
array variable.ndarray.tolist()
method on the array myarray
. The output is assigned to a new variable mylist
.mylist
.type()
function to check for the data type of the object variable mylist
.