You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>>np.result_type(7, np.array([1], np.float32))
dtype('float32') # Ok, the scalar value '7' does not impact type promotion per NEP50>>>np.result_type(type(7), np.array([1], np.float32))
dtype('float64') # Surprisingly, the *type* of the scalar value '7' does impact promotion# Similar situations happen with Python's float and complex types.
What I assume happens is that Python's int type is converted internally to an np.int64 (this is on a 64-bit system):
>>>np.result_type(int)
dtype('int64')
, and np.int64 is then used for the type promotion.
However, I could not find this scenario explained in the docs.
I'd suggest adding an explanation to Data type promotion in NumPy, perhaps in the "Exceptions to the general promotion rules" section. I'd be happy to open a PR if that is helpful.
The text was updated successfully, but these errors were encountered:
Not really an oversight, although one could have tried to change it. It just keeps doing what it always does, np.dtype(int) being the default integer dtype.
Within the context of result_type not going there would make sense, but in general np.dtype(int) probably needs to keep working, so...
This is probably what you had in mind, but just to spell it out - could the rules be changed to "Like scalar values, Python's scalar types don't influence the result type"?
Uh oh!
There was an error while loading. Please reload this page.
Issue with current documentation:
After reading Data type promotion in NumPy, NEP50, and Changes to NumPy data type promotion, the following type promotion scenario with Python's builtin scalar types (i.e., not scalar values) is still surprising to me:
What I assume happens is that Python's
int
type is converted internally to annp.int64
(this is on a 64-bit system):, and
np.int64
is then used for the type promotion.However, I could not find this scenario explained in the docs.
cc @inducer
Idea or request for content:
I'd suggest adding an explanation to Data type promotion in NumPy, perhaps in the "Exceptions to the general promotion rules" section. I'd be happy to open a PR if that is helpful.
The text was updated successfully, but these errors were encountered: