
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'>
Comments
Powered by Markdown