These 2 do not work because there are no variables with these names in your workspace:
y5 = x.astype(float64)
I get a NameError: name 'float64' is not defined . The error is generated by the Python interpreter before anything is passed to the x.astype method.
You will get the same error if you only entered float64 in the interactive interpreter.
np.float64 works because there is such a variable in the np namespace. This is really a numpy class.
float also works. This is also a class, basic Python (it can also be used as a function, converting a string or number to a float object).
'float64' is a string that astype understands, possibly looking at something in a table. (I could see it).
On the other hand, if I give astype some random string, I get another error
In [967]: A.astype('bar') ... TypeError: data type "bar" not understood
np.dtype('bar') gives the same error.
np.dtype(float) np.dtype('float64') np.dtype('float')
all return the same dtype('float64') object dtype('float64') .
source share