[Numpy-discussion] Applying logical operations along an axis of a boolean array?
sebastian at sipsolutions.net
Mon Dec 18 09:58:58 EST 2017
On Mon, 2017-12-18 at 12:02 +0100, hanno_lists at gmx.net wrote:
> is it possible, to apply a logical operation, such as AND or OR along
> a particular axis of a numpy array?
As mentioned, `np.any` and `np.all` work. However, what is more/also
interesting to you is maybe that:
works. All binary ufuncs (most elementwise functions such as addition,
subtraction, multiplication, etc. support this `reduce` (and some
other, please find out yourself ;)) methods.
So that thing like `any`, `sum`, or `cumsum` are actually just thin
wrappers around those.
> Let's say I have an (n,m) array and I want to AND along the first
> axis, such that I get a (1,m) (or just (m,) dimensional array back. I
> looked at the documentation for np.logical_and and friends but
> couldn't find an axis keyword on the logical_xyz operations and
> nothing else seemed to fit.
> Thanks, and best regards,
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 801 bytes
Desc: This is a digitally signed message part
More information about the NumPy-Discussion