4 ms·
Even that took me a while to understand it and, I guess, is another example of Numpy’s absurdity. My initial thought was “None of the examples have arguments t
by Someone 4y ago
Even that took me a while to understand it and, I guess, is another example of Numpy’s absurdity.
My initial thought was “None of the examples have arguments that are equal to each other, so that should evaluate to false.any()”, but that would mean all should return the same value, so that can’t be true, so I figured out that Numpy overloads/changes a == b to do item-by-item comparison on arrays, and return an array of booleans.
But then, the statement “This really only makes sense when `a` is a scalar” doesn’t make sense to me. That seems to indicate Numpy also overloads a == b as a comparison of each element of a with a single value b and vice versa, but that doesn’t make sense, given that arrays can contain arrays, making it impossible to discriminate between [1,2] as a two-item sequence and [1,2] as a single-item sequence where the item is a two-item sequence.
Reading https://stackoverflow.com/questions/10580676/comparing-two-numpy-arrays-for-equality-element-wise https://stackoverflow.com/questions/10580676/comparing-two-n... further strengthens my impression that one should avoid using == in Numpy.