Change the data type of an array using NumPy

In this python numpy program, we will change the data type of an array using NumPy.

Steps to solve the program
  1. Import the numpy library as np.
  2. Create an array using np.array().
  3. Change the data type of an array using astype(float) and store the result in another variable.
  4. 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.]]
				
			

find the indices of the minimum value of an array.

find the ith element of an array.

Leave a Comment