There seems to be a subtle difference between numpy.float
and numpy.float64
.
>>> import numpy as np
>>> isinstance(2.0, np.float)
True
>>> isinstance(2.0, np.float64)
False
Can someone clarify this? Thanks
np.float
is an alias for python float
type.
np.float32
and np.float64
are numpy specific 32 and 64-bit float types.
float?
Init signature: float(self, /, *args, **kwargs)
Docstring:
float(x) -> floating point number
Convert a string or number to a floating point number, if possible.
Type: type
np.float?
Init signature: np.float(self, /, *args, **kwargs)
Docstring:
float(x) -> floating point number
Convert a string or number to a floating point number, if possible.
Type: type
np.float32?
Init signature: np.float32(self, /, *args, **kwargs)
Docstring: 32-bit floating-point number. Character code 'f'. C float compatible.
File: c:\python\lib\site-packages\numpy\__init__.py
Type: type
np.float64?
Init signature: np.float64(self, /, *args, **kwargs)
Docstring: 64-bit floating-point number. Character code 'd'. Python float compatible.
File: c:\python\lib\site-packages\numpy\__init__.py
Type: type
Thus, when you do isinstance(2.0, np.float)
, it is equivalent to isinstance(2.0, float)
as 2.0 is a plain python built-in float type... and not the numpy type.
isinstance(np.float64(2.0), np.float64)
would obviously be True
.
float64
. When I converted the departure delay time type from int64
to match the arrival delay type, I didn't catch that I used fillna().astype('float')
and the data/scatter plot changed a lot. I couldn't figure out what was going on. When I corrected it to fillna().astype('float64')
all was good. Not sure why it made such a difference when all the values looked like 55.00, 130.00
etc.
This would seem to be the difference between a 32-bit floating point number and a 64-bit floating point number (in C, a float vs. a double), and 2.0 ends up being a 32-bit floating point number.
numpy.float
is Python's float class. Do you meannumpy.float_
with an underscore at the end? That is the same asnumpy.float64
.