>>> numpy.float64(5.9975).hex()
'0x1.7fd70a3d70a3dp+2'
>>> (5.9975).hex()
'0x1.7fd70a3d70a3dp+2'

They are the same number. What differs is the textual representation obtained via by their __repr__ method; the native Python type outputs the minimal digits needed to uniquely distinguish values, while NumPy code before version 1.14.0, released in 2018 didn't try to minimise the number of digits output.

Answer from Ignacio Vazquez-Abrams on Stack Overflow
Top answer
1 of 2
69
>>> numpy.float64(5.9975).hex()
'0x1.7fd70a3d70a3dp+2'
>>> (5.9975).hex()
'0x1.7fd70a3d70a3dp+2'

They are the same number. What differs is the textual representation obtained via by their __repr__ method; the native Python type outputs the minimal digits needed to uniquely distinguish values, while NumPy code before version 1.14.0, released in 2018 didn't try to minimise the number of digits output.

2 of 2
3

Numpy float64 dtype inherits from Python float, which implements C double internally. You can verify that as follows:

isinstance(np.float64(5.9975), float)   # True

So even if their string representation is different, the values they store are the same.

On the other hand, np.float32 implements C float (which has no analog in pure Python) and no numpy int dtype (np.int32, np.int64 etc.) inherits from Python int because in Python 3 int is unbounded:

isinstance(np.float32(5.9975), float)   # False
isinstance(np.int32(1), int)            # False

So why define np.float64 at all?

np.float64 defines most of the attributes and methods in np.ndarray. From the following code, you can see that np.float64 implements all but 4 methods of np.array:

[m for m in set(dir(np.array([]))) - set(dir(np.float64())) if not m.startswith("_")]

# ['argpartition', 'ctypes', 'partition', 'dot']

So if you have a function that expects to use ndarray methods, you can pass np.float64 to it while float doesn't give you the same.

For example:

def my_cool_function(x):
    return x.sum()

my_cool_function(np.array([1.5, 2]))   # <--- OK
my_cool_function(np.float64(5.9975))   # <--- OK
my_cool_function(5.9975)               # <--- AttributeError
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.4 Manual
Python’s floating-point numbers are usually 64-bit floating-point numbers, nearly equivalent to numpy.float64. In some unusual situations it may be useful to use floating-point numbers with more precision.
Discussions

which data type should I use for most accurate calculations? float decimal or python?
Floats are great but unreliable - they have small imprecisions that can quickly add up. More on reddit.com
🌐 r/learnpython
7
1
March 25, 2023
numpy - Compare `float` and `float64` in python - Stack Overflow
I have to compare two numbers. One of them comes from regulat python code and comes other from numpy. Debugger shows they have same value '29.0', but type of first is float and type of second is fl... More on stackoverflow.com
🌐 stackoverflow.com
January 31, 2020
python - Difference between numpy.float and numpy.float64 - Stack Overflow
That is the same as numpy.float64. ... I meant numpy.float without underscore. Would you elaborate your comments, maybe into an answer? ... np.float is an alias for python float type. More on stackoverflow.com
🌐 stackoverflow.com
[Week 1] np.float vs float
regarding Exercise 2 for this function : conv_single_step() I converted the last value Z to float the value is correct but the datatype is worng which cause the test to fail. what do I miss? More on community.deeplearning.ai
🌐 community.deeplearning.ai
1
0
August 26, 2022
🌐
Medium
medium.com › @amit25173 › understanding-numpy-float64-a300ac9e096a
Understanding numpy.float64. If you think you need to spend $2,000… | by Amit Yadav | Medium
February 8, 2025 - Higher Precision: Python’s default float uses 64-bit precision, but NumPy’s float64 specifically guarantees that your floating-point numbers have the highest possible precision for calculations.
🌐
Python⇒Speed
pythonspeed.com › articles › float64-float32-precision
The problem with float32: you only get 16 million values
February 1, 2023 - In contrast, 64-bit floats give you 253 = ~9,000,000,000,000,000 values. This is a much larger number than 16 million. So how do you fit float64s into float32s without losing precision?
🌐
Quora
quora.com › What-are-the-differences-between-float32-and-float64
What are the differences between float32 and float64? - Quora
Answer (1 of 6): A floating point number has 3 different parts: 1. The floating point’s position (i.e. where the dot exists within the number). 2. The actual number (known as mantissa). 3. Whether it’s negative or positive. Part 3 is always 1 bit, it’s either 0 (positive) or 1 (negative).
🌐
Quora
quora.com › What-is-np-float32-and-np-float64-in-numpy-in-simple-terms
What is np.float32 and np.float64 in numpy in simple terms? - Quora
Answer (1 of 2): np.float32 - It means that each value in the numpy array would be a float of size 32 bits. np.float64- It means that each value in the numpy array would be a float of size 64.
Find elsewhere
🌐
DeepLearning.AI
community.deeplearning.ai › course q&a › deep learning specialization › convolutional neural networks
[Week 1] np.float vs float - Convolutional Neural Networks - DeepLearning.AI
August 26, 2022 - regarding Exercise 2 for this function : conv_single_step() I converted the last value Z to float the value is correct but the datatype is worng which cause the test to fail. what do I miss?
🌐
GitHub
github.com › samuelcolvin › pydantic › issues › 1879
numpy.float64 is not converted to float · Issue #1879 · pydantic/pydantic
August 28, 2020 - pydantic version: 1.6.1 pydantic ... python version: 3.7.7 (default, Jun 9 2020, 17:58:51) [GCC 8.3.0] platform: Linux-4.19.76-linuxkit-x86_64-with-debian-10.4 optional deps. installed: ['email-validator'] In the code below, I would expect the numpy.float64 to be converted to a float by the Foo ...
Author   dewolfarno
🌐
NumPy
numpy.org › doc › 2.1 › user › basics.types.html
Data types — NumPy v2.1 Manual
Floating point numbers offer a larger, but inexact, range of possible values. >>> np.power(100, 100, dtype=np.int64) # Incorrect even with 64-bit int 0 >>> np.power(100, 100, dtype=np.float64) 1e+200 · Python’s floating-point numbers are usually 64-bit floating-point numbers, nearly equivalent ...
🌐
GitHub
github.com › numpy › numpy › issues › 21906
`np.float64` is not accepted as `float` under static type checks · Issue #21906 · numpy/numpy
July 2, 2022 - # Python version 3.8.10, numpy version 1.23.0 import numpy as np x = np.float64(1.0) print(f"x={x} of type={type(x)} is float: {isinstance(x, float)}") # x=1.0 of type=<class 'numpy.float64'> is float: True def f(a: float) -> float: return a f(x) """ pyright 1.1.256: error: Argument of type "float64" cannot be assigned to parameter "a" of type "float" in function "f" "float64" is incompatible with "float" (reportGeneralTypeIssues) mypy 0.961: error: Argument 1 to "f" has incompatible type "floating[_64Bit]"; expected "float" """
Author   0xjc
🌐
Scientific Python
discuss.scientific-python.org › contributor & development discussion › scipy
Should scipy tests assume float64 as the default floating-point dtype? - scipy - Scientific Python
December 13, 2024 - Hi, Historically, scipy assumed that the default floating-point type is a double-precision float64. Now that we’re moving towards the array API world, we face torch and jax which default to float32, unless explicitly asked. Thus, there’s a question of how we test scipy on these new frameworks.
🌐
Edureka Community
edureka.co › home › community › categories › python › difference between python float and numpy float32
Difference between Python float and numpy float32 | Edureka Community
March 4, 2019 - What is the difference between the built in float and numpy.float32? For example, here is a code: ... > 58682.8 What is the built in float format?
🌐
GitHub
github.com › Unidata › netcdf4-python › issues › 926
variable attributes: float32 vs float64, int32 vs int64 · Issue #926 · Unidata/netcdf4-python
May 7, 2019 - However, when defining a variable attribute whose value is a floating-point via setncattr, the result is a 64-bit floating-point ("double"). (The result of ncdump shows "1." instead of "1.f", indicating a double instead of a float.)
Author   ghost
🌐
NumPy
numpy.org › devdocs › user › basics.types.html
Data types — NumPy v2.5.dev0 Manual
Python’s floating-point numbers are usually 64-bit floating-point numbers, nearly equivalent to numpy.float64. In some unusual situations it may be useful to use floating-point numbers with more precision.
🌐
GitHub
github.com › numpy › numpy › issues › 5272
Data type precision problems? · Issue #5272 · numpy/numpy
November 11, 2014 - >>> import numpy >>> numpy.version.version '1.9.0' >>> a = numpy.array([3991.86795711963],dtype='float64') >>> print a [ 3991.86795712] >>> print numpy.float32(a) [ 3991.86791992] >>> print numpy.float64(a) 3991.86795712 ; # Why does this print statement look different to the above (float32) - no brackets >>> a = numpy.array([3991.86795711963],dtype='float128') >>> print numpy.float128(a) [ 3991.868] ; # Why is this truncated when it should have double the precision of float64?
Author   durack1
🌐
CSDN
devpress.csdn.net › python › 63045fb87e6682346619ab50.html
Difference between numpy.float and numpy.float64_python_Mangs-Python
August 23, 2022 - Answer a question 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 someo Mangs Python