Convert an array of float datatype to integer

In this python numpy program, we will convert an array of float datatype to integer.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Convert an array having values as float datatype to an integer using astype(int).
  4. 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]]
				
			

access an array by column.

add an extra column to an array.

Leave a Comment