import numpy as np
np.double is np.float64 # returns True

As you can see they are virtually the same

You can see that in the docs here where it is mentioned that np.float64 is just an alias for np.double

Answer from Ofer Sadan on Stack Overflow
Discussions

failure to convert numpy.float64 into System.Double
Environment Pythonnet version: 3.0 Python version: 3.x Operating System: Windows/Linux .NET Runtime: x Details Passing in a numpy array to a C# function that takes a double[] parameter fails. pytho... More on github.com
🌐 github.com
24
September 12, 2022
Converting numpy float64 of python float to Decimal is not the same (get rounded in numpy case)
Converting numpy float64 of python float to Decimal is not the same (get rounded in numpy case)#1833 ... Describe what you were trying to get done. I had to convert floats to Decimal but somehow the current Double I got out of Decimal when looking at it using ToDouble would give me only the ... More on github.com
🌐 github.com
June 24, 2022
floating point - How to convert 64-bit to double decimal in Python? - Stack Overflow
Using Python, how can I get the decimal floating-point value out from a 64-bit bit pattern? I think I need to use struct, but how can I get it right? Here is what I have tried: struct.unpack('<... More on stackoverflow.com
🌐 stackoverflow.com
March 17, 2020
floating point - convert double to float in Python - Stack Overflow
In a Python program, I have these two values: v1 = 0.00582811585976 v2 = 0.00582811608911 My hypothesis is that v1 is a 64-bits floating point value, and v2 is v1 converted to a 32-bits floating p... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › pythonnet › pythonnet › issues › 1887
Cannot convert Numpy Float64 array to double[] · Issue #1887 · pythonnet/pythonnet
July 25, 2022 - // call PythonEngine.Initialize() and set PythonHome and Paths correctly using (Py.GIL()) { PyModule scope = Py.CreateScope(); scope.Exec( "import numpy as np \n" + "arr = np.array([1., 2.])" ); PyObject arr = scope.Get("arr"); Type dataType = typeof(double[]); var array = arr.AsManagedObject(dataType); // CollectionAssert.AreEqual(new double[] { 1.0, 2.0 }, (double[])result); } This throws an InvalidCastException in AsManagedObject: System.InvalidCastException: cannot convert object to target type ---> Python.Runtime.PythonException: 'numpy.float64' value cannot be converted to System.Double
Author: pythonnet
🌐
GitHub
github.com › pythonnet › pythonnet › issues › 1936
failure to convert numpy.float64 into System.Double · Issue #1936 · pythonnet/pythonnet
September 12, 2022 - python code: test_array = np.array([123, 345], np.float) CSharpClass.Test(test_array) C# code public static void Test(double[] TestData) {...} I already have a fix for this issue. ... internal static bool PyFloat_Check(BorrowedReference ob) { return PyObject_TypeCheck(ob, PyFloatType); //return PyObject_TYPE(ob) == PyFloatType; // existing code } This will convert any type that is derived from PyFloatType, which includes numpy.float64
Author: pythonnet
🌐
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.
🌐
Codingzap
codingzap.com › home › blog – programming & coding articles › convert string to double in python| 3 methods explained
Convert String to Double in Python| 3 Methods Explained
June 27, 2026 - This can be another great alternative to change to Double from String in Python. ... We have to first call the Numpy in the program as NP to make it easy to use multiple times. Now, we will take a String Value with the decimal number in any variable. Using the syntax np.float64(Variable-Name), we will convert ...
🌐
FavTutor
favtutor.com › blogs › convert-string-to-double-python
Convert String to Double in Python (3 Easy Methods)
October 27, 2022 - Note how the dtype for the "Fee" column has changed from 'int64' to 'float64'.(Although to be converted into double this should be float64 or float128, it also has float32 with it.) To know more about ways to convert string to Python check out 6 Ways to Convert String to Float in Python.
Find elsewhere
🌐
IONOS UK
ionos.co.uk › digital guide › websites › web development › converting python strings to floats
How to convert Python strings to floats - IONOS UK
January 2, 2025 - If, on the other hand, you want to convert a float into a string, you can use the str() function. This function converts other values into strings. float_number = 3.1416 string_number = str(float_number) print(string_number) # Output: "3.1416"python
🌐
Reddit
reddit.com › r/python › double precision
r/Python on Reddit: Double precision
October 17, 2019 - Is there a simple way to change the default Python precision without having to rewrite all my code? Thank you all in advance! Archived post. New comments cannot be posted and votes cannot be cast. Share ... All Python floats are double precision by default.
🌐
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 problem involves writing a NumPy program to convert NumPy data types (dtypes) to native Python types. The task requires using NumPy's type conversion functions to transform NumPy-specific data types, such as numpy.int32 or numpy.float32, into their equivalent native Python types, like int or float.
🌐
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. Whether this is possible in numpy depends on the hardware and on the development environment: specifically, x86 machines provide hardware floating-point with 80-bit precision, and while most C compilers provide this as their long double type, MSVC (standard for Windows builds) makes long double identical to double (64 bits).
Top answer
1 of 3
8

Yes, actually when you use Python's native float to specify the dtype for an array , numpy converts it to float64. As given in documentation -

Note that, above, we use the Python float object as a dtype. NumPy knows that int refers to np.int_, bool means np.bool_ , that float is np.float_ and complex is np.complex_. The other data-types do not have Python equivalents.

And -

float_ - Shorthand for float64.

This is why even though you use float to convert the whole array to float , it still uses np.float64.

According to the requirement from the other question , the best solution would be converting to normal float object after taking each scalar value as -

float(new_array[0])

A solution that I could think of is to create a subclass for float and use that for casting (though to me it looks bad). But I would prefer the previous solution over this if possible. Example -

In [20]: import numpy as np

In [21]: na = np.array([1., 2., 3.])

In [22]: na = np.array([1., 2., 3., np.inf, np.inf])

In [23]: type(na[-1])
Out[23]: numpy.float64

In [24]: na[-1] - na[-2]
C:\Anaconda3\Scripts\ipython-script.py:1: RuntimeWarning: invalid value encountered in double_scalars
  if __name__ == '__main__':
Out[24]: nan

In [25]: class x(float):
   ....:     pass
   ....:

In [26]: na_new = na.astype(x)


In [28]: type(na_new[-1])
Out[28]: float                           #No idea why its showing float, I would have thought it would show '__main__.x' .

In [29]: na_new[-1] - na_new[-2]
Out[29]: nan

In [30]: na_new
Out[30]: array([1.0, 2.0, 3.0, inf, inf], dtype=object)
2 of 3
3

You can create an anonymous type float like this

>>> new_array = my_array.astype(type('float', (float,), {}))
>>> type(new_array[0])
<type 'float'>
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.5 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. Whether this is possible in numpy depends on the hardware and on the development environment: specifically, x86 machines provide hardware floating-point with 80-bit precision, and while most C compilers provide this as their long double type, MSVC (standard for Windows builds) makes long double identical to double (64 bits).
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.