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

Sebastian Berg sebastian at sipsolutions.net
Fri Sep 12 03:48:06 EDT 2014


On Do, 2014-09-11 at 22:54 -0700, Antony Lee wrote:
> 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?
> 

`np.asarray([array([1, 2]), array([1])])` is an object array, not a
boolean array. You probably want to concatenate them.

- Sebastian


> Thanks,
> Antony
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140912/f9d88b4c/attachment.sig>


More information about the NumPy-Discussion mailing list