🌐
NumPy
numpy.org › doc › stable › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.5 Manual
Whenever a data-type is required ... dtype constructor: What can be converted to a data-type object is described below: ... Used as-is. ... The default data type: float64....
🌐
NumPy
numpy.org › doc › stable › user › basics.types.html
Data types — NumPy v2.5 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.
🌐
W3Schools
w3schools.com › python › numpy › numpy_data_types.asp
NumPy Data Types
The astype() function creates a copy of the array, and allows you to specify the data type as a parameter. The data type can be specified using a string, like 'f' for float, 'i' for integer etc.
🌐
NumPy
numpy.org › devdocs › user › basics.types.html
Data types — NumPy v2.6.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.
🌐
NumPy
numpy.org › doc › 1.22 › user › basics.types.html
Data types — NumPy v1.22 Manual
Data-types can be used as functions to convert python numbers to array scalars (see the array scalar section for an explanation), python sequences of numbers to arrays of that type, or as arguments to the dtype keyword that many numpy functions or methods accept. Some examples: >>> import numpy as np >>> x = np.float32(1.0) >>> x 1.0 >>> y = np.int_([1,2,4]) >>> y array([1, 2, 4]) >>> z = np.arange(3, dtype=np.uint8) >>> z array([0, 1, 2], dtype=uint8)
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_data_types.htm
NumPy - Data Types
Original array: [1.1 2.2 3.3 4.4 5.5] Original dtype: float64 Converted array: [1 2 3 4 5] Converted dtype: int32 · You can also specify the data type during array creation to avoid the need to convert the type later. Now, we are creating an array of integers by specifying the float data type using the numpy.float32() function −
🌐
Medium
mr-amit.medium.com › changing-data-type-dtype-in-numpy-arrays-a-step-by-step-guide-ea7e323e1959
Changing Data Type (dtype) in NumPy Arrays: A Step-by-Step Guide | by It's Amit | Medium
March 6, 2025 - 2. 3.] print("New dtype:", float_array.dtype) # Output: float64 · See that? Your original array is untouched, which is great for keeping your data safe. ... You might be wondering: What if there’s a rogue element in my array that doesn’t fit the target dtype? Well, NumPy will immediately throw a ValueError to let you know something went wrong.
🌐
Python for Data Science
python4data.science › en › latest › workspace › numpy › dtype.html
dtype - Python for Data Science
May 15, 2026 - import numpy as np rng = np.random.default_rng() data = rng.random((7, 3)) dt = data.dtype dt · [1]: dtype('float64') NumPy data types: Determine the number of elements with itemsize: [2]: dt.itemsize · [2]: 8 · Determine the name of the data type: [3]: dt.name ·
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: astype() to change dtype of an array | note.nkmk.me
February 4, 2024 - NumPy: Round up/down array elements (np.floor, np.trunc, np.ceil) In addition to explicit type conversion with astype(), implicit type conversion can occur during operations. For example, division with the / operator returns float even between integers. a_int = np.array([1, 2, 3]) a_float = np.array([1.0, 2.0, 3.0]) print((a_int / a_int).dtype) # float64 print((a_int / a_float).dtype) # float64
🌐
NumPy
numpy.org › doc › 2.1 › reference › arrays.dtypes.html
Data type objects (dtype) — NumPy v2.1 Manual
Whenever a data-type is required ... dtype constructor: What can be converted to a data-type object is described below: ... Used as-is. ... The default data type: float64....
Find elsewhere
🌐
APXML
apxml.com › courses › essential-numpy-pandas › chapter-2-getting-started-numpy-arrays › array-data-types
NumPy Array Data Types (dtypes)
Original Array: [1.1 2.7 3.5 4.9] Original dtype: float64 Converted to int32: [1 2 3 4] New dtype: int32 Numeric Array: [ 0 1 5 0 -2] Converted to bool: [False True True False True] New dtype: bool Converted to string: [b'1' b'2' b'3' b'4'] New dtype: |S11 · Caution: Be mindful when using astype(). Converting from a float to an integer truncates the decimal part, it doesn't round. Converting from a higher-precision type (like float64) to a lower-precision one (like float32) can lead to loss of precision. Converting to a type with a smaller range (like int64 to int8) can lead to unexpected results or errors if the values exceed the target type's limits. Understanding NumPy's data types is a fundamental step.
🌐
NumPy
numpy.org › doc › 2.2 › user › basics.types.html
Data types — NumPy v2.2 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. The other data-types do not have Python equivalents.
🌐
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. The other data-types do not have Python equivalents.
🌐
NumPy
numpy.org › doc › 1.14 › user › basics.types.html
Data types — NumPy v1.14 Manual
Data-types can be used as functions to convert python numbers to array scalars (see the array scalar section for an explanation), python sequences of numbers to arrays of that type, or as arguments to the dtype keyword that many numpy functions or methods accept. Some examples: >>> import numpy as np >>> x = np.float32(1.0) >>> x 1.0 >>> y = np.int_([1,2,4]) >>> y array([1, 2, 4]) >>> z = np.arange(3, dtype=np.uint8) >>> z array([0, 1, 2], dtype=uint8)
Top answer
1 of 2
9

Looks like an unfortunate accident: someone decided that dtype(None) would "default" to float (though dtype() is an error). Then someone else wrote dtype.__eq__ such that it converts its second argument to a dtype before comparing. So dtype(float) == None is dtype(float) == dtype(None) which is true.

You can see a comment in the source code here: descriptor.c#L1217

  • Get typenum from an object -- None goes to NPY_DEFAULT_TYPE

And of course NPY_DEFAULT_TYPE is float (at least usually).

As for the __eq__ operator, it's here: descriptor.c#L3317. It does what I outlined:

if (!PyArray_DescrCheck(other)) {
    if (PyArray_DescrConverter(other, &new) == NPY_FAIL) {
        return NULL;
    }
}

So that's a conversion from whatever is on the right-hand side of == to a dtype object, via the converter function mentioned before, which turns None into dtype(float).

Edit: I found this pretty interesting and it seems like an accident, so I created a patch and submitted to the maintainers: https://github.com/numpy/numpy/pull/4532 .

2 of 2
4

if you want to compare an arbitrary object against exactly None in python you need to use:

object is None

Like in this case any object may override its comparison operator to not do what you are expecting.

As for why, dtype('float64') is equivalent to None in the context of dtypes in the same way dtypes are equivalent to typestrings

np.dtype('i4') == 'i4'
True

Equality is not identity.

As for why dtype(None) == dtype('float64'), many functions in numpy have dtype=None keyword arguments. In most cases this means default dtype which is dtype(None). An example is np.zeros. But there are exceptions, e.g. when the dtype can be inferred from the arguments, like in the case of np.arange(10) where the default dtype will be of integer type (np.intp I think).

🌐
NumPy
numpy.org › doc › 2.2 › reference › arrays.promotion.html
Data type promotion in NumPy — NumPy v2.2 Manual
The result dtype has a precision as low as possible without appearing to the left of either input dtype in the diagram. Note the following specific rules and observations: When a Python float or complex interacts with a NumPy integer the result will be float64 or complex128 (yellow border).
🌐
NumPy
numpy.org › doc › 1.15 › user › basics.types.html
Data types — NumPy v1.15 Manual
Data-types can be used as functions to convert python numbers to array scalars (see the array scalar section for an explanation), python sequences of numbers to arrays of that type, or as arguments to the dtype keyword that many numpy functions or methods accept. Some examples: >>> import numpy as np >>> x = np.float32(1.0) >>> x 1.0 >>> y = np.int_([1,2,4]) >>> y array([1, 2, 4]) >>> z = np.arange(3, dtype=np.uint8) >>> z array([0, 1, 2], dtype=uint8)
🌐
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 › @pritioli › essential-numpy-data-types-a-must-know-guide-ad3657f708b7
Essential NumPy Data Types: A Must-Know Guide | by Code & Cognition | Medium
December 22, 2023 - complex-floating point 'c' or complex128 complex numbers with 128-bit precision · timedelta 'm' or timedelta64 differences between two dates or times · datetime 'M' or datetime64 dates and times with 64-bit precision · (Python) objects 'O' or object fixed-length Unicode strings. Unicode string 'U' or str_ fixed-length string (Unicode string) raw data 'V' or void : useful for a structured array · A solid understanding of NumPy dtypes empowers practitioners to make informed decisions, ensuring efficiency and precision across a spectrum of scientific computing tasks.