In this python numpy program, we will convert an array of float datatype to integer.
Steps to solve the program
- Import the numpy library as np.
- Create an array using np.array().
- Convert an array having values as float datatype to an integer using astype(int).
- Print the output.
import numpy as np
x = np.array([[6.7, 5.2],[9.4, 2.7]])
print("Float array: \n",x)
print("Integer array: \n",x.astype(int))
Output :
Float array:
[[6.7 5.2]
[9.4 2.7]]
Integer array:
[[6 5]
[9 2]]