[Numpy-discussion] np.where: x and y need to have the same shape as condition ?
Benjamin Root
ben.root@ou....
Tue Jan 29 16:19:53 CST 2013
On Tue, Jan 29, 2013 at 6:16 AM, denis <denis-bz-gg@t-online.de> wrote:
> Folks,
> the doc for `where` says "x and y need to have the same shape as
> condition"
> http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.where.html
> But surely
> "where is equivalent to:
> [xv if c else yv for (c,xv,yv) in zip(condition,x,y)]"
> holds as long as len(condition) == len(x) == len(y) ?
> And `condition` can be broadcast ?
> n = 3
> all01 = np.array([ t for t in np.ndindex( n * (2,) )]) # 000 001 ...
> x = np.zeros(n)
> y = np.ones(n)
> w = np.where( all01, y, x ) # 2^n x n
>
> Can anyone please help me understand `where`
> / extend "where is equivalent to ..." ?
> Thanks,
> cheers
> -- denis
>
>
Do keep in mind the difference between len() and shape (they aren't the
same for 2 and greater dimension arrays). But, ultimately, yes, the arrays
have to have the same shape, or use scalars. I haven't checked
broadcast-ability though. Perhaps a note should be added into the
documentation to explicitly say whether the arrays can be broadcastable.
Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130129/48fbc3f6/attachment.html
More information about the NumPy-Discussion
mailing list