Write a NumPy program that changes the type of array.
Source Code:
import numpy as np
ary = np.array([5,10,15,20])
print("Array is:\n",ary)
print("Type of array is:",ary.dtype)
ary = ary.astype('f')
print("Array is:\n",ary)
print("Type of array is:",ary.dtype)
Sample Output:ary = np.array([5,10,15,20])
print("Array is:\n",ary)
print("Type of array is:",ary.dtype)
ary = ary.astype('f')
print("Array is:\n",ary)
print("Type of array is:",ary.dtype)
Array is:
[ 5 10 15 20]
Type of array is: int32
Array is:
[ 5. 10. 15. 20.]
Type of array is: float32
[ 5 10 15 20]
Type of array is: int32
Array is:
[ 5. 10. 15. 20.]
Type of array is: float32