Even if I looked it up on the web, I couldn't find the contents easily, so I made a note (it's really short ...)
>> import numpy as np
>> np.where(A>5, 1, -1)
Is there a code? I thought
>> import numpy as np
###First of all, make an array
>> A = np.arange(10,0,-1)
###Content confirmation
>> A
array([10,  9,  8,  7,  6,  5,  4,  3,  2,  1])
###Let's check from the inside
>> A>5
[ True  True  True  True  True False False False False False]
### ->If the condition is met, True is returned, and if not, False is returned.
###Try to bite where
>> np.where(A>5)
(array([0, 1, 2, 3, 4]),)
### ->You have extracted the elements that meet the conditions.
###Well, the content of the theme
>> np.where(A>5, 1, -1)
array([ 1,  1,  1,  1,  1, -1, -1, -1, -1, -1])
### ->If the condition is met, the value of the second argument"1", If not satisfied, the value of the third argument"-1"Seems to return
###Check the contents of ↑ with other values just in case
>> np.where(A>5,2,0)
array([2, 2, 2, 2, 2, 0, 0, 0, 0, 0])
### ->It looks like it fits.
```
 Does it feel like a SQL `where` clause? (is that different?!)
 Reference
 --Official document:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html
 ↑ Based on this article, does it help you understand a little? !!
        Recommended Posts