>>> 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
Discussions

Numpy float64 vs Python float - Stack Overflow
Note also that the Pandas read_csv ... string-to-float conversion that is not correctly rounded. Thus after exporting a value and re-reading it, the recovered value may end up being 1 or 2 ulps different from the original. ... 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 ... More on stackoverflow.com
🌐 stackoverflow.com
BUG: Shouldn't numpy's floating types (e.g. `np.float_`) and python's native `float` type be compatible?
Describe the issue: When trying to type hint functions accepting scalars, I get unexpected error messages from my type checker (Pylance). As np.float_ is a subtype of python's native float type, I ... More on github.com
🌐 github.com
9
April 25, 2023
Preventing numpy from converting float type to numpy.int64 type
Numpy arrays have a defined data type. eta_hat is an array of dtype int64, because that's how you initialized it in the first place: as the docs say, if no type is given explicitly then "the type will be determined as the minimum type required to hold the objects in the sequence". So the solution is to explicitly make it an array of floats... More on reddit.com
🌐 r/learnpython
3
1
April 3, 2023
Prevent numpy array from turning my floats into strings
numpy arrays are homogenous, i.e. they require that every element has the same type. Since calling asarray() on a list of tuples results in a 2 dimensional array, I assume this is why your values are being coerced. (as a sidenote, if I were to try to fix this by saying list5=list5.astype(float) it will convert to float in the console, however when I call list5 again it is back to numpy_string! anyone know why?) Assigning newarray = oldarray.astype(float) works as expected for me, however it converts every element to a float, including the ones that were originally strings. If this is what you wanted, then you can solve the problem by setting list1 = map(float, [list of strings])) to begin with. More on reddit.com
🌐 r/learnpython
7
10
May 5, 2015
🌐
GeeksforGeeks
geeksforgeeks.org › python › float-in-python
float() in Python - GeeksforGeeks
September 18, 2025 - NumPy · Pandas · Practice · Django · Flask · Last Updated : 18 Sep, 2025 · In Python, the float() function is used to convert numbers or numeric strings into floating-point numbers.
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.4 Manual
There are 5 basic numerical types ... is the number of bits that are needed to represent a single value in memory. For example, numpy.float64 is a 64 bit floating point data type....
Find elsewhere
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 › 2.1 › reference › generated › numpy.float_power.html
numpy.float_power — NumPy v2.1 Manual
>>> x1 = range(6) >>> x1 [0, 1, 2, 3, 4, 5] >>> np.float_power(x1, 3) array([ 0., 1., 8., 27., 64., 125.])
🌐
W3Schools
w3schools.com › python › numpy › numpy_data_types.asp
NumPy Data Types
NumPy Editor NumPy Quiz NumPy Exercises ... "ABCD" integer - used to represent integer numbers. e.g. -1, -2, -3 · float - used to represent real numbers....
🌐
NumPy
numpy.org › doc › 1.22 › user › basics.types.html
Data types — NumPy v1.22 Manual
NumPy numerical types are instances ... There are 5 basic numerical types representing booleans (bool), integers (int), unsigned integers (uint) floating point (float) and complex....
🌐
GeeksforGeeks
geeksforgeeks.org › python › using-numpy-to-convert-array-elements-to-float-type
Using NumPy to Convert Array Elements to Float Type - GeeksforGeeks
July 15, 2025 - Explanation: Here, an integer array a is converted to a float array res using np.float64(), which casts the elements to 64-bit floating-point numbers efficiently. This approach reuses the astype() method like before, but here you overwrite the original array with the converted one. It’s a form of in-place reassignment, not true in-place conversion which NumPy doesn’t support due to fixed data types .
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.finfo.html
numpy.finfo — NumPy v2.1 Manual
Kind of floating point or complex floating point data-type about which to get information. ... The equivalent for integer data types. ... For developers of NumPy: do not instantiate this at the module level. The initial calculation of these parameters is expensive and negatively impacts import ...
🌐
Hyperskill
hyperskill.org › learn › step › 10095
Data types in NumPy
Hyperskill is an educational platform for learning programming and software development through project-based courses, that helps you secure a job in tech. Master Python, Java, Kotlin, and more with real-world coding challenges.
🌐
Medium
medium.com › @amit25173 › different-ways-to-convert-numpy-float-to-int-f47f3be42453
Different Ways to Convert NumPy Float to Int | by Amit Yadav | Medium
April 12, 2025 - The easiest and most common way to convert floats to integers in NumPy is by using .astype(int).
🌐
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. Use float64 when your calculations require higher accuracy, especially when dealing with large datasets or sensitive computations. ... You can easily check the type of a NumPy array by using the .dtype attribute.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.astype.html
numpy.ndarray.astype — NumPy v2.5.dev0 Manual
When casting from complex to float or int. To avoid this, one should use a.real.astype(t). ... Try it in your browser! >>> import numpy as np >>> x = np.array([1, 2, 2.5]) >>> x array([1.
🌐
GitHub
github.com › numpy › numpy › issues › 23663
BUG: Shouldn't numpy's floating types (e.g. `np.float_`) and python's native `float` type be compatible? · Issue #23663 · numpy/numpy
April 25, 2023 - As np.float_ is a subtype of python's native float type, I would expect to be able to pass a variable with type np.float_ when a native float is expected. import numpy as np def idx(x: float) -> float: return x arr = np.arange(5.0, dtype=np.float_) sum = np.sum(arr) idx(sum)
Author   simonaltrogge
🌐
Reddit
reddit.com › r/learnpython › preventing numpy from converting float type to numpy.int64 type
r/learnpython on Reddit: Preventing numpy from converting float type to numpy.int64 type
April 3, 2023 - Numpy arrays have a defined data type. eta_hat is an array of dtype int64, because that's how you initialized it in the first place: as the docs say, if no type is given explicitly then "the type will be determined as the minimum type required to hold the objects in the sequence". So the solution is to explicitly make it an array of floats:
🌐
NumPy
numpy.org › doc › 1.14 › user › basics.types.html
Data types — NumPy v1.14 Manual
Which is more efficient depends on hardware and development environment; typically on 32-bit systems they are padded to 96 bits, while on 64-bit systems they are typically padded to 128 bits. np.longdouble is padded to the system default; np.float96 and np.float128 are provided for users who want specific padding.
🌐
Reddit
reddit.com › r/learnpython › prevent numpy array from turning my floats into strings
r/learnpython on Reddit: Prevent numpy array from turning my floats into strings
May 5, 2015 -

Let's say I have 5 lists, list1, list2, list3, list4, list5.

The first 3 are lists of strings e.g. while the last 2 are lists of floats e.g.

list1  = ['1','2','3'...] 
list2 = list3 = list1
list4 = [1.0,2.0,3.0...]
list5 = list4

All lists are the same length.

I'd like to turn them into a numpy array, while preserving their original datatypes. I say

intermediateList = zip(list1,list2,list3,list4,list5)

which gives me a list (length=5) of lists, with the original data types preserved. Perfect.

However, when I try to convert to numpy.array

myArray=asarray(intermediateList)

numPy converts everything into numpy_string type, which is very irritating. I can now no longer perform numerical operations on list4 and list5 without re-converting the values to float.

(as a sidenote, if I were to try to fix this by saying

list5=list5.astype(float)

it will convert to float in the console, however when I call list5 again it is back to numpy_string! anyone know why?)

Any suggestions?