w3resource logo

:

Python Exercises

Python NumPy: Convert a NumPy array into Python list structure

Python NumPy: Array Object Exercise-80 with Solution

Write a Python program to convert a NumPy array into Python list structure.

Sample Solution:-

Python Code:

import numpy as np
x= np.arange(6).reshape(3, 2)
print("Original array elements:")
print(x)
print("Array to list:")
print(x.tolist())

Sample Output:

Original array elements:                                                               
[[0 1]                                                                                 
 [2 3]                                                                                 
 [4 5]]                                                                                
Array to list:                                                                         
[[0, 1], [2, 3], [4, 5]]

Python Code Editor:

Improve this sample solution and post your code through Disqus