dpnp.ndarray.tolist
method
- ndarray.tolist()
Converts the array to a (possibly nested) Python list.
For full documentation refer to
numpy.ndarray.tolist.- Returns:
out -- The possibly nested Python list of array elements.
- Return type:
Examples
For a 1D array,
a.tolist()is almost the same aslist(a), except thattolistchanges 0D arrays to Python scalars:>>> import dpnp as np >>> a = np.array([1, 2]) >>> list(a) [array(1), array(2)] >>> a.tolist() [1, 2]
Additionally, for a 2D array,
tolistapplies recursively:>>> a = np.array([[1, 2], [3, 4]]) >>> list(a) [array([1, 2]), array([3, 4])] >>> a.tolist() [[1, 2], [3, 4]]
The base case for this recursion is a 0D array:
>>> a = np.array(1) >>> list(a) Traceback (most recent call last): ... TypeError: iteration over a 0-d array >>> a.tolist() 1