Q:

Write a NumPy program to change the data type of an array

0

Write a NumPy program to change the data type of an array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.array([[2, 4, 6], [6, 8, 10]], np.int32)
print(x)
print("Data type of the array x is:",x.dtype)
# Change the data type of x
y = x.astype(float)
print("New Type: ",y.dtype)
print(y)

Sample Output:

[[ 2  4  6]                                                            
 [ 6  8 10]]                                                           
Data type of the array x is: int32                                     
New Type:  float64                                                     
[[  2.   4.   6.]                                                      
 [  6.   8.  10.]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now