Changing the data type of an array

Question Q6.1.4

Explain the following behaviour:

In [x]: a, b = np.zeros((3,)), np.ones((3,))
In [x]: a.dtype = 'int'
In [x]: a
Out[x]: array([0, 0, 0])
In [x]: b.dtype = 'int'
In [x]: b
Out[x]: array([4607182418800017408, 4607182418800017408, 4607182418800017408])

What is the correct way to convert an array of one data type to an array of another?


Solution Q6.1.4