[SciPy-User] numpy.where() issue

Oleksandr Huziy guziy.sasha at gmail.com
Wed Jul 15 14:29:34 EDT 2015


Just to save you possible frustration later:

'|' is used instead of 'or'

'&' is used instead of 'and'

'~' is used instead of 'not'

Cheers



2015-07-15 14:27 GMT-04:00 Oleksandr Huziy <guziy.sasha at gmail.com>:

> Maybe this way would be clearer (remember parentheses in the condition are
> crucial):
>
> """
> indices = np.where((Yy > 0.02) | (Yy < -0.02))
> """
>
> Cheers
>
>
> 2015-07-15 14:22 GMT-04:00 Sebastian <sebix at sebix.at>:
>
>>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA256
>>
>> Hi,
>>
>> What is this doing? np.where(Yy > 0.02 or Yy < -0.02)
>> Let's split it up
>> (Yy > 0.02) or (Yy < -0.02)
>> The both < > comparisons give boolean numpy arrays, say a and b.
>> a or b
>> The python or-Operator works on boolean values, so it does
>> bool(a) or bool(b)
>> What is "The truth value of an array with more than one element"? It "is
>> ambiguous".
>> Voila
>>
>> You can also use
>> np.logical_or(np.where(...), np.where(...))
>> or shorter
>> np.where(...) | np.where(...)
>>
>> Sebastian
>>
>> On 07/15/2015 08:13 PM, Gabriele Brambilla wrote:
>> > I have problems with numpy.where
>> >
>> > why if I write
>> > deathnote0 = np.where(Yy > 0.02 or Yy < -0.02)
>> > I get:
>> >
>> > Traceback (most recent call last):
>> >
>> >   File "readingK.py", line 63, in <module>
>> >
>> >     deathnote0 = np.where(Yy > 0.02 or Yy < -0.02)
>> >
>> > ValueError: The truth value of an array with more than one element is
>> ambiguous. Use a.any() or a.all()
>> >
>> > while if I do
>> >
>> > deathnote0 = np.where(Yy > 0.02)
>> >
>> > deathnote1 = np.where(Yy < -0.02)
>> >
>> > deathnote = deathnote0 + deathnote1
>> >
>> > it works?
>> >
>> >
>> > thanks
>> >
>> >
>> > Gabriele
>> >
>> >
>> >
>> >
>> > _______________________________________________
>> > SciPy-User mailing list
>> > SciPy-User at scipy.org
>> > http://mail.scipy.org/mailman/listinfo/scipy-user
>> >
>> > --
>> > python programming - mail server - photo - video - https://sebix.at
>> > To verify my cryptographic signature or send me encrypted mails, get my
>> > key at https://sebix.at/DC9B463B.asc and on public keyservers.
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v2.0.22 (GNU/Linux)
>>
>> iQIcBAEBCAAGBQJVpqThAAoJEBn0X+vcm0Y7x00P/ioF2JTIXCrwW0IGHWqbEIah
>> i+LAoBFle0pJItuSY3VCOA9Ut57YG8BKqs37hA/9dK3yQqGGwPGLx9ETGk6V8du8
>> qeoY4vCx7yYvoLFyysDNJZtyztpW2hCXjhy9ZhrlG75MzO/8W2VJ1k5b/moyUXfn
>> sIcscCFI36Jt3lo4kySRDk7NqlzEg2opkXp1o053dIrSLQbQWLaihc2gio2MgtvB
>> aYIDwPZ0fGaWNB/5o+nYkGOiT+fYez6pIqNbk7fUlQ4/i6U7z8/BddZbig5tlGw6
>> taho+44xcML8cndMWYiL4NlYTp4GOy0x4YcAeG6osyuJPc36flaRhxEACTV7JjO/
>> raHckH93l4hN/8l+m6hBh9vqkSCLtMIeJ3pXUKCqptWv8mRC3lB7u+pWNVU3iysI
>> iRuv5DoCIQ15IgNDK42n7nsuM5JLEchrTBQn5twG2A5gjM7Q/IZvOhMlqycBN8Is
>> xr4vZBwwgV+0tsxGdKnkeateIxo/lhtZjx4yjHgpMiDTxIB5gFVfDs1eowj1Glcm
>> AE085May/sJHhAY5rGEBFO+yjtApKHKoKWSLFAzV7nO14kXuPxF73OP8rJdb+FAK
>> czhqbShX74tICugQTsfwg0+032gyx8eMj4mjnIjBGUMIPTYBuAzh+SFNZBHQNguO
>> 15Rahq3Uf0zFCofVMYZO
>> =3gGp
>> -----END PGP SIGNATURE-----
>>
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>
>
>
> --
> Sasha
>



-- 
Sasha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150715/8c2e8e33/attachment.html>


More information about the SciPy-User mailing list