>>> 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
Note that, above, we could have used the Python float object as a dtype instead of numpy.float64. NumPy knows that int refers to numpy.int_, bool means numpy.bool, that float is numpy.float64 and complex is numpy.complex128.
Discussions

python - Difference between numpy.float and numpy.float64 - Stack Overflow
There seems to be a subtle difference between numpy.float and numpy.float64. More on stackoverflow.com
🌐 stackoverflow.com
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
`np.float64` is not accepted as `float` under static type checks
Some of the built-in scalar types inherit from the corresponding Python types. However, this fact does not seem to be exposed by the numpy type stubs. # Python version 3.8.10, numpy version 1.23.0 ... More on github.com
🌐 github.com
3
July 2, 2022
[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
🌐
Oreate AI
oreateai.com › blog › understanding-the-differences-between-npfloat64-and-float-in-python › 70eb57300f95ddff64bc58eac70fe3d7
Understanding the Differences Between np.float64 and Float in Python - Oreate AI Blog
January 15, 2026 - On the other hand, float is a built-in type in Python that typically also corresponds to double-precision (which usually means it's equivalent to 64 bits on most systems). So far so good; but where do things diverge?
🌐
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 - The main difference lies in precision. float64 uses 64 bits, offering more precision (about 15–17 decimal places) than float32, which uses only 32 bits and is limited to around 7 decimal places.
🌐
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.
🌐
NumPy
numpy.org › devdocs › user › basics.types.html
Data types — NumPy v2.5.dev0 Manual
Note that, above, we could have used the Python float object as a dtype instead of numpy.float64. NumPy knows that int refers to numpy.int_, bool means numpy.bool, that float is numpy.float64 and complex is numpy.complex128.
Find elsewhere
🌐
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
🌐
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?
🌐
CSDN
devpress.csdn.net › python › 63045fb87e6682346619ab50.html
Difference between numpy.float and numpy.float64_python_Mangs-Python
August 23, 2022 - np.float is an alias for python float type. np.float32 and np.float64 are numpy specific 32 and 64-bit float types.
🌐
GitHub
github.com › samuelcolvin › pydantic › issues › 1879
numpy.float64 is not converted to float · Issue #1879 · pydantic/pydantic
August 28, 2020 - In the code below, I would expect the numpy.float64 to be converted to a float by the Foo pydantic object.
Author   dewolfarno
🌐
NumPy
numpy.org › doc › 2.1 › user › basics.types.html
Data types — NumPy v2.1 Manual
Note that, above, we could have used the Python float object as a dtype instead of numpy.float64. NumPy knows that int refers to numpy.int_, bool means numpy.bool, that float is numpy.float64 and complex is numpy.complex128.
🌐
NumPy
numpy.org › doc › 1.22 › user › basics.types.html
Data types — NumPy v1.22 Manual
Python’s floating-point numbers are usually 64-bit floating-point numbers, nearly equivalent to np.float64. In some unusual situations it may be useful to use floating-point numbers with more precision.
🌐
Netgen/NGSolve
forum.ngsolve.org › t › performance-issue-using-float-vs-np-float64 › 3240
Performance Issue using float vs. np.float64 - NGSolve - Netgen/NGSolve
February 4, 2025 - Hello everybody, I just came across some unexpected performance behavior of NGSolve that might be interesting. When building a matrix from two existing matrices, it makes a huge difference if one multiplies with a Python float or a numpy.float64. I created a minimal working example (MWE) to test on your machine.
🌐
Python⇒Speed
pythonspeed.com › articles › float64-float32-precision
The problem with float32: you only get 16 million values
February 1, 2023 - Libraries like NumPy and Pandas let you switch data types, which allows you to reduce memory usage. Switching from numpy.float64 (“double-precision” or 64-bit floats) to numpy.float32 (“single-precision” or 32-bit floats) cuts memory ...
🌐
GitHub
github.com › Theano › Theano › issues › 1913
float64 is faster than float32?? · Issue #1913 · Theano/Theano
June 12, 2014 - It seems using float64 is faster than float32 in matrix muliplication. I got the better result using float32 only if I used Out(sandbox.cuda.basic_ops.gpu_from_host(a*b),borrow=True). Should I use float64 rather than float32? I'm really ...
Author   junku901
🌐
GitHub
github.com › numpy › numpy › issues › 5272
Data type precision problems? · Issue #5272 · numpy/numpy
November 10, 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
Top answer
1 of 8
51

CPython floats are allocated in chunks

The key problem with comparing numpy scalar allocations to the float type is that CPython always allocates the memory for float and int objects in blocks of size N.

Internally, CPython maintains a linked list of blocks each large enough to hold N float objects. When you call float(1) CPython checks if there is space available in the current block; if not it allocates a new block. Once it has space in the current block it simply initializes that space and returns a pointer to it.

On my machine each block can hold 41 float objects, so there is some overhead for the first float(1) call but the next 40 run much faster as the memory is allocated and ready.

Slow numpy.float32 vs. numpy.float64

It appears that numpy has 2 paths it can take when creating a scalar type: fast and slow. This depends on whether the scalar type has a Python base class to which it can defer for argument conversion.

For some reason numpy.float32 is hard-coded to take the slower path (defined by the _WORK0 macro), while numpy.float64 gets a chance to take the faster path (defined by the _WORK1 macro). Note that scalartypes.c.src is a template which generates scalartypes.c at build time.

You can visualize this in Cachegrind. I've included screen captures showing how many more calls are made to construct a float32 vs. float64:

float64 takes the fast path

float32 takes the slow path

Updated - Which type takes the slow/fast path may depend on whether the OS is 32-bit vs 64-bit. On my test system, Ubuntu Lucid 64-bit, the float64 type is 10 times faster than float32.

2 of 8
23

Operating with Python objects in a heavy loop like that, whether they are float, np.float32, is always slow. NumPy is fast for operations on vectors and matrices, because all of the operations are performed on big chunks of data by parts of the library written in C, and not by the Python interpreter. Code run in the interpreter and/or using Python objects is always slow, and using non-native types makes it even slower. That's to be expected.

If your app is slow and you need to optimize it, you should try either converting your code to a vector solution that uses NumPy directly, and is fast, or you could use tools such as Cython to create a fast implementation of the loop in C.