NumPy | tolist method
tolist(~) method converts a Numpy array to a standard Python list.
Both methods convert a Numpy array to a standard Python list. However, the
list(arr) method does not perform the conversion recursively, that is, if your Numpy array is 2D for instance, then only the outer array would become converted into a list with the inner Numpy array left as is. In contrast, the
arr.tolist() will convert both the outer and inner arrays to a Numpy array.
See examples below for clarification.
This method does not take any parameter.
A standard Python list.
a = np.array([5,6,7])a.tolist()[5, 6, 7]
a = np.array([[5,6],[7,8]])a.tolist()[[5, 6], [7, 8]]
This is contrast to