|
|
Subscribe / Log in / New account

NumPy 1.20 has been released

NumPy 1.20 has been released

Posted Feb 24, 2021 9:03 UTC (Wed) by quietbritishjim (subscriber, #114117)
Parent article: NumPy 1.20 has been released

Isn't the new where argument:

    np.any(ri < 3, where=ri%2 == 0)
the same as using the existing logical_and:
    np.any(np.logical_and(ri < 3, ri%2 == 0))
? If so, is there any benefit to the new notation? I suppose perhaps speed? I see it's slightly more consise, but the composing two functions seems clearer to me and is much more flexible.


to post comments

NumPy 1.20 has been released

Posted Feb 24, 2021 14:05 UTC (Wed) by leephillips (subscriber, #100450) [Link] (1 responses)

As far as I can tell the results should be the same. This is an extension of the `where` keyword argument that was added to `numpy.reduce` in v. 1.17. Both when using the `where` keyword argument in when using `logical_and`, the Boolean mask array is broadcast to match the dimensions of the array in the first argument. There could be performance differences.

NumPy 1.20 has been released

Posted Feb 24, 2021 14:49 UTC (Wed) by mhvk (subscriber, #86585) [Link]

Indeed, it just extends `where` to the wrappers around ufunc reductions (`np.logical_and.reduce` and `np.logical_or.reduce` in this case), really remedying an oversight from when I implemented `where` for reductions... I think the advantage is clearer for taking the mean, etc. For `any` and `all`, what would be nice is to have proper short-circuiting, but that is still on the wish list.

p.s. What makes `ndarray` so particularly nice is how it deals with strides to allow views of many forms into the array. This is nicely described in the "array programming with numpy" article; see https://ui.adsabs.harvard.edu/abs/2020Natur.585..357H/abs...

NumPy 1.20 has been released

Posted Feb 25, 2021 6:59 UTC (Thu) by cozzyd (guest, #110972) [Link]

You probably avoid a copy too, which can be significant if it's a big array?


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds