In this python numpy program, we will change the data type of an array using NumPy.
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Change the data type of an array using astype(float) and store the result in another variable.
- Print the output.
import numpy as np
x = np.array([[4,8,7],[2,3,6]])
print("Old: \n",x)
y = x.astype(float)
print("New: \n",y)
Output :
Old:
[[4 8 7]
[2 3 6]]
New:
[[4. 8. 7.]
[2. 3. 6.]]