In this python numpy program, we will convert an array into a list using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Convert an array into a list using tolist() and store the result in a variable.
- Print the output.
import numpy as np
x = np.array([[3,0],
[6,4]])
print("Matrix: \n",x)
y = x.tolist()
print("List: ",y)
Output :
Matrix:
[[3 0]
[6 4]]
List: [[3, 0], [6, 4]]