Issues with "Mixing arrays and Python scalars" section
See original GitHub issueA few issues with the mixing arrays and Python scalars section that came up from testing:
- The matmul operator (
@
) does not (and should not) support scalar types, so it should be excluded. - Should boolean arrays be required to work with arithmetic operators. NumPy gives errors in some cases, for example:
>>> import numpy as np
>>> np.array(False) - False
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: numpy boolean subtract, the `-` operator, is not supported, use the bitwise_xor, the `^` operator, or the logical_xor function instead.
- How should casting work? For example,
int8 array + large Python int
. Should it cast the int, or give an error. Or should this be unspecified. - The above question also applies for Python float -> float32 casting, which is implicitly supported by the text that is currently there, but is unsafe in general (is there a “safe” variant of float64 -> float32, or is it always unsafe? Either way, this would be value based casting, which I thought we were trying to avoid).
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (14 by maintainers)
Top Results From Across the Web
Future NumPy behavior when mixing arrays, NumPy scalars ...
In this poll we ask for your opinion on how NumPy should work when arrays, NumPy scalars, and Python scalars are mixed.
Read more >deprecate scalar conversions for rank>0 arrays · Issue #10404
I'm fine with rank-0 conversions, but I found that discrimination of conversion based on array size can easily lead to inconsistencies ...
Read more >numpy - "Only size-1 arrays can be converted to Python scalars"
A python scalar is just one number. An array with 2 numbers can be converted into just one, can it? But which line...
Read more >NEP 50 — Promotion rules for Python scalars - NumPy
The reason is that value-based promotion is disabled when all objects are scalars or 0-D arrays. NumPy thus returns the same type as...
Read more >Chapter 4. NumPy Basics: Arrays and Vectorized Computation
Operations between Arrays and Scalars ... Arrays are important because they enable you to express batch operations on data without writing any for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Unsigned integer overflow is technically undefined behavior in C/C++, and that seems to work out OK. It’s not great, but I think these inconsistencies are mostly an indication that nobody expects Python’s big ints to do something sensible when combined with fixed size arrays.
Right, we intentionally deviated from NumPy here. There is no notion of separate “scalar” types, and 0d arrays are not treated differently from other arrays.
On Wed, Dec 16, 2020 at 5:29 PM Aaron Meurer notifications@github.com wrote: