Convert an NumPy array to a Python list
You can convert a NumPy array to a Python list.
import numpy
a = numpy.array([1, 2, 3, 4, 5, 6])
b = numpy.array([[1, 2, 3], [4, 5, 6]])
a2 = list(a)
b2 = list(b)
print(a2) # [1, 2, 3, 4, 5, 6]
print(b2) # [array([1, 2, 3]), array([4, 5, 6])]
print(type(b2)) # <class 'list'>
for i in b2:
print(type(i)) # <class 'numpy.ndarray'>
NumPy Array
- Addition / subtraction
- Add a NumPy array and Python integer
- Dimension of array
- Zero array
- Make an arithmetic progression
- Get random integers
- get the value of a given index
- Sort an array
- Split an array
- Iterate an array
- NumPy where
- Get the subarray of an array satisfying a condition
- Sum all the elements in an array by columns or rows
- Count non-zero elements
- Get the index of the max value
- Convert the 2D or 3D array to 1D array
- Convert 1D array to 2D array
- Convert an NumPy array to a Python list
- Concatenate arrays
- Delete the elements from an array