[Numpy-discussion] Broadcasting with np.logical_and.reduce

Antony Lee antony.lee at berkeley.edu
Fri Sep 12 01:54:37 EDT 2014


Hi,
I thought that ufunc.reduce performs broadcasting, but it seems a bit
confused by boolean arrays:

<ipython with pylab mode on>
In [1]: add.reduce([array([1, 2]), array([1])])
Out[1]: array([2, 3])
In [2]: logical_and.reduce([array([True, False], dtype=bool), array([True],
dtype=bool)])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-bedbab4c13e1> in <module>()
----> 1 logical_and.reduce([array([True, False], dtype=bool), array([True],
dtype=bool)])

ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()

Am I missing something here?

Thanks,
Antony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140911/86332c93/attachment.html>


More information about the NumPy-Discussion mailing list