NumPy Input and Output: ndarray.tolist() function
numpy.ndarray.tolist() function
The ndarray.tolist() function is used to get the array as a (possibly nested) list.
Syntax:
ndarray.tolist()
Version: 1.15.0
Returns: y : list
The possibly nested list of array elements.
Notes:
The array may be recreated, a = np.array(a.tolist()).
NumPy.ndarray.tolist() method Example-1:
>>> import numpy as np
>>> x = np.array([2, 4])
>>> x.tolist()
Output:
[2, 4]
NumPy.ndarray.tolist() method Example-2:
>>> import numpy as np
>>> x = np.array([[2, 4], [6, 8]])
>>> list(x)
Output:
[array([2, 4]), array([6, 8])]
NumPy.ndarray.tolist() method Example-3:
>>> import numpy as np
>>> x = np.array([[2, 4], [6, 8]])
>>> list(x)
>>> x.tolist()
Output:
[[2, 4], [6, 8]]
Python - NumPy Code Editor:
Previous: ndarray.tofile() function
Next: fromfile() function
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework