Use val.item() to convert most NumPy values to a native Python type:

import numpy as np

# for example, numpy.float32 -> python float
val = np.float32(0)
pyval = val.item()
print(type(pyval))         # <class 'float'>

# and similar...
type(np.float64(0).item()) # <class 'float'>
type(np.uint32(0).item())  # <class 'int'>
type(np.int16(0).item())   # <class 'int'>
type(np.cfloat(0).item())  # <class 'complex'>
type(np.datetime64(0, 'D').item())  # <class 'datetime.date'>
type(np.datetime64('2001-01-01 00:00:00').item())  # <class 'datetime.datetime'>
type(np.timedelta64(0, 'D').item()) # <class 'datetime.timedelta'>
...

(A related method np.asscalar(val) was deprecated with 1.16, and removed with 1.23).


For the curious, to build a table of conversions of NumPy array scalars for your system:

for name in dir(np):
    obj = getattr(np, name)
    if hasattr(obj, 'dtype'):
        try:
            if 'time' in name:
                npn = obj(0, 'D')
            else:
                npn = obj(0)
            nat = npn.item()
            print('{0} ({1!r}) -> {2}'.format(name, npn.dtype.char, type(nat)))
        except:
            pass

There are a few NumPy types that have no native Python equivalent on some systems, including: clongdouble, clongfloat, complex192, complex256, float128, longcomplex, longdouble and longfloat. These need to be converted to their nearest NumPy equivalent before using .item().

Answer from Mike T on Stack Overflow
Top answer
1 of 13
574

Use val.item() to convert most NumPy values to a native Python type:

import numpy as np

# for example, numpy.float32 -> python float
val = np.float32(0)
pyval = val.item()
print(type(pyval))         # <class 'float'>

# and similar...
type(np.float64(0).item()) # <class 'float'>
type(np.uint32(0).item())  # <class 'int'>
type(np.int16(0).item())   # <class 'int'>
type(np.cfloat(0).item())  # <class 'complex'>
type(np.datetime64(0, 'D').item())  # <class 'datetime.date'>
type(np.datetime64('2001-01-01 00:00:00').item())  # <class 'datetime.datetime'>
type(np.timedelta64(0, 'D').item()) # <class 'datetime.timedelta'>
...

(A related method np.asscalar(val) was deprecated with 1.16, and removed with 1.23).


For the curious, to build a table of conversions of NumPy array scalars for your system:

for name in dir(np):
    obj = getattr(np, name)
    if hasattr(obj, 'dtype'):
        try:
            if 'time' in name:
                npn = obj(0, 'D')
            else:
                npn = obj(0)
            nat = npn.item()
            print('{0} ({1!r}) -> {2}'.format(name, npn.dtype.char, type(nat)))
        except:
            pass

There are a few NumPy types that have no native Python equivalent on some systems, including: clongdouble, clongfloat, complex192, complex256, float128, longcomplex, longdouble and longfloat. These need to be converted to their nearest NumPy equivalent before using .item().

2 of 13
45

If you want to convert (numpy.array OR numpy scalar OR native type OR numpy.darray) TO native type you can simply do :

converted_value = getattr(value, "tolist", lambda: value)()

tolist will convert your scalar or array to python native type. The default lambda function takes care of the case where value is already native.

🌐
w3resource
w3resource.com › python-exercises › numpy › basic › numpy-basic-exercise-41.php
NumPy: Convert numpy dtypes to native python types - w3resource
August 28, 2025 - This process ensures compatibility between NumPy arrays and standard Python operations by enabling seamless data type conversions. ... # Importing the NumPy library with an alias 'np' import numpy as np # Printing a message indicating conversion from numpy.float32 to Python float print("numpy.float32 to python float") # Creating a numpy.float32 value 'x' initialized to 0 x = np.float32(0) # Printing the type of 'x' print(type(x)) # Extracting the Python float value from the numpy.float32 'x' using the item() method pyval = x.item() # Printing the type of the extracted Python float value 'pyval' print(type(pyval))
Discussions

BUG: Weird conversion behavior from np.float32 to Python float
Describe the issue: I found out that converting np.float32 to a Python float via .item() gives a weird result. While I understand NumPy retains the float32 internal representation of the value, I f... More on github.com
🌐 github.com
February 16, 2024
Convert list of numpy.float64 to float in Python quickly - Stack Overflow
What is the fastest way of converting a list of elements of type numpy.float64 to type float? I am currently using the straightforward for loop iteration in conjunction with float(). I came acros... More on stackoverflow.com
🌐 stackoverflow.com
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: eta_hat = numpy.array( [ [0], [0], [0] ], dtype=float) More on reddit.com
🌐 r/learnpython
3
1
April 3, 2023
BUG: Shouldn't numpy's floating types (e.g. `np.float_`) and python's native `float` type be compatible?
Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. ... There was an error while loading. Please reload this page. ... BUG: Shouldn't numpy's floating types (e.g. np.float_) and python's native float type be compatible?#23663 More on github.com
🌐 github.com
9
April 25, 2023
🌐
GitHub
github.com › numpy › numpy › issues › 14150
How to convert np.float32 to Python float easily? · Issue #14150 · numpy/numpy
July 29, 2019 - Hi, I try to convert np.float32 to a Python float in my project, and I find it's not eaisly. I have to convert it to str and then convert to float. Here is the code: import numpy as np x = np.float32(1.9) x.tolist() # 1.899999976158142 x.item() # 1.899999976158142 x.view() # 1.9 str(x) # '1.9' float(str(x)) # 1.9 ·
🌐
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, a is converted ... keeping the original. np.vectorize() turns a regular Python function like float() into a NumPy-style function that can operate element-wise over arrays....
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.5 Manual
There are some exceptions, such as when code requires very specific attributes of a scalar or when it checks specifically whether a value is a Python scalar. Generally, problems are easily fixed by explicitly converting array scalars to Python scalars, using the corresponding Python type function (e.g., int, float, complex, str).
🌐
GitHub
github.com › numpy › numpy › issues › 25836
BUG: Weird conversion behavior from np.float32 to Python float · Issue #25836 · numpy/numpy
February 16, 2024 - As a quirk of our coercion logic, when you combine 0-D arrays and scalars, they are treated both as scalars. The biggest precision wins, so the LHS gets cast up to np.float64 before doing the comparison; you are implicitly requesting the cast up to np.float64 by using a float object on the RHS.
🌐
YouTube
youtube.com › codeflare
Python format casts numpy float32 into Python float - YouTube
Download this code from https://codegive.com Title: Converting numpy.float32 to Python float using format()In Python, the numpy library is widely used for nu...
Published: November 26, 2023
Views: 14
Find elsewhere
Top answer
1 of 3
32

The tolist() method should do what you want. If you have a numpy array, just call tolist():

In [17]: a
Out[17]: 
array([ 0.        ,  0.14285714,  0.28571429,  0.42857143,  0.57142857,
        0.71428571,  0.85714286,  1.        ,  1.14285714,  1.28571429,
        1.42857143,  1.57142857,  1.71428571,  1.85714286,  2.        ])

In [18]: a.dtype
Out[18]: dtype('float64')

In [19]: b = a.tolist()

In [20]: b
Out[20]: 
[0.0,
 0.14285714285714285,
 0.2857142857142857,
 0.42857142857142855,
 0.5714285714285714,
 0.7142857142857142,
 0.8571428571428571,
 1.0,
 1.1428571428571428,
 1.2857142857142856,
 1.4285714285714284,
 1.5714285714285714,
 1.7142857142857142,
 1.857142857142857,
 2.0]

In [21]: type(b)
Out[21]: list

In [22]: type(b[0])
Out[22]: float

If, in fact, you really have python list of numpy.float64 objects, then @Alexander's answer is great, or you could convert the list to an array and then use the tolist() method. E.g.

In [46]: c
Out[46]: 
[0.0,
 0.33333333333333331,
 0.66666666666666663,
 1.0,
 1.3333333333333333,
 1.6666666666666665,
 2.0]

In [47]: type(c)
Out[47]: list

In [48]: type(c[0])
Out[48]: numpy.float64

@Alexander's suggestion, a list comprehension:

In [49]: [float(v) for v in c]
Out[49]: 
[0.0,
 0.3333333333333333,
 0.6666666666666666,
 1.0,
 1.3333333333333333,
 1.6666666666666665,
 2.0]

Or, convert to an array and then use the tolist() method.

In [50]: np.array(c).tolist()
Out[50]: 
[0.0,
 0.3333333333333333,
 0.6666666666666666,
 1.0,
 1.3333333333333333,
 1.6666666666666665,
 2.0]

If you are concerned with the speed, here's a comparison. The input, x, is a python list of numpy.float64 objects:

In [8]: type(x)
Out[8]: list

In [9]: len(x)
Out[9]: 1000

In [10]: type(x[0])
Out[10]: numpy.float64

Timing for the list comprehension:

In [11]: %timeit list1 = [float(v) for v in x]
10000 loops, best of 3: 109 µs per loop

Timing for conversion to numpy array and then tolist():

In [12]: %timeit list2 = np.array(x).tolist()
10000 loops, best of 3: 70.5 µs per loop

So it is faster to convert the list to an array and then call tolist().

2 of 3
11

You could use a list comprehension:

floats = [float(np_float) for np_float in np_float_list]
🌐
AskPython
askpython.com › python › string › python-string-float-conversion
Python String to float, float to String - AskPython
February 28, 2020 - Python provides us with the built-in float() method to convert the data type of input from String to float. ... inp = '99.23' print("Input string:\n",inp) opt = float(inp) print('Input value after converting it to float type:\n',opt) ...
🌐
w3resource
w3resource.com › python-exercises › numpy › python-numpy-exercise-7.php
NumPy: Array converted to a float type - w3resource
August 29, 2025 - Write a NumPy program to convert an array to a floating type. ... # Importing the NumPy library with an alias 'np' import numpy as np # Defining a Python list 'a' containing integers a = [1, 2, 3, 4] # Printing the original array 'a' print("Original array") print(a) # Converting the array 'a' to a NumPy array of type float using asfarray() x = np.asfarray(a) # Printing the array 'x' after converting to a float type print("Array converted to a float type:") print(x)
🌐
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 -

So I have 3-tuple of only float types, let's call it eta.

I also have a class attribute eta_hat which is initialized as numpy.array( [ [0], [0], [0] ] ), the idea it being a column vector.

My goal is to make the values of eta_hat the values of eta. However, the piece of code

self.eta_hat[0][0], self.eta_hat[1][0], self.eta_hat[2][0] = eta[0], eta[1], eta[2]

converts eta[x] from float to numpy.int64 in self.eta_hat[x][0]. I do not understand how numpy handles these, and would love an explenation on how I could fix this problem. Thanks!

🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › array › astype()
Python Numpy array astype() - Convert Data Type
November 8, 2024 - Such conversion can reduce memory usage, important for handling large datasets. The astype() function in NumPy makes it possible to convert the data type of array elements seamlessly.
🌐
IncludeHelp
includehelp.com › python › convert-list-or-numpy-array-of-single-element-to-float.aspx
Python - Convert list or NumPy array of single element to float
December 23, 2023 - If we want to convert it into a float, we can call the defined function where we can write a code to apply float() method on the item. ... # Import numpy import numpy as np # Creating a numpy array arr = np.array([4]) # Display original array print("Original Array:\n", arr, "\n") # Converting ...
🌐
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: numpy
🌐
Google Groups
groups.google.com › g › cython-users › c › Ubh2nG0_R9g
Converting float * to numpy array
What about numpy.frombuffer()? I've used that function successfully with a ctypes array. import numpy as np import ctypes buffer = (ctypes.c_float * 100) # do something with buffer a = np.frombuffer(buffer, np.float32) ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
🌐
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?
Top answer
1 of 2
63

Python's standard float type is a C double: http://docs.python.org/2/library/stdtypes.html#typesnumeric

NumPy's standard numpy.float is the same, and is also the same as numpy.float64.

2 of 2
3

Data type-wise numpy floats and built-in Python floats are the same, however boolean operations on numpy floats return np.bool_ objects, which always return False for val is True. Example below:

In [1]: import numpy as np
   ...: an_np_float = np.float32(0.3)
   ...: a_normal_float = 0.3
   ...: print(a_normal_float, an_np_float)
   ...: print(type(a_normal_float), type(an_np_float))

0.3 0.3
<class 'float'> <class 'numpy.float32'>

Numpy floats can arise from scalar output of array operations. If you weren't checking the data type, it is easy to confuse numpy floats for native floats.

In [2]: criterion_fn = lambda x: x <= 0.5
   ...: criterion_fn(a_normal_float), criterion_fn(an_np_float)

Out[2]: (True, True)

Even boolean operations look correct. However the result of the numpy float isn't a native boolean datatype, and thus can't be truthy.


In [3]: criterion_fn(a_normal_float) is True, criterion_fn(an_np_float) is True
Out[3]: (True, False)

In [4]: type(criterion_fn(a_normal_float)), type(criterion_fn(an_np_float))
Out[4]: (bool, numpy.bool_)

According to this github thread, criterion_fn(an_np_float) == True will evaluate properly, but that goes against the PEP8 style guide.

Instead, extract the native float from the result of numpy operations. You can do an_np_float.item() to do it explicitly (ref: this SO post) or simply pass values through float().

🌐
GitHub
github.com › pythonnet › pythonnet › issues › 1833
Converting numpy float64 of python float to Decimal is not the same (get rounded in numpy case) · Issue #1833 · pythonnet/pythonnet
June 24, 2022 - Python.NET 2.x permits all sorts of conversions in attempts to match the function arguments, some of which permit data loss. Please, try 3.0 previews of Python.NET. I believe 3.0 will tell you your Decimal(np.float64) call has no matching constructor overloads forcing you to explicitly convert np.float64 to either Python float or to System.Double first.
🌐
NumPy
numpy.org › doc › 1.22 › user › basics.types.html
Data types — NumPy v1.22 Manual
There are some exceptions, such as when code requires very specific attributes of a scalar or when it checks specifically whether a value is a Python scalar. Generally, problems are easily fixed by explicitly converting array scalars to Python scalars, using the corresponding Python type function (e.g., int, float, complex, str, unicode).
🌐
NumPy
numpy.org › devdocs › user › basics.types.html
Data types — NumPy v2.6.dev0 Manual
There are some exceptions, such as when code requires very specific attributes of a scalar or when it checks specifically whether a value is a Python scalar. Generally, problems are easily fixed by explicitly converting array scalars to Python scalars, using the corresponding Python type function (e.g., int, float, complex, str).