Numpy np.where multiple condition
<p>I need to work with multiple condition using numpy.</p>

<p>I'm trying this code that seem to work. </p>

<p>My question is: There is another alternative that can do the same job? </p>

<pre><code>Mur=np.array([200,246,372])*pq.kN*pq.m
Mumax=np.array([1400,600,700])*pq.kN*pq.m
Mu=np.array([100,500,2000])*pq.kN*pq.m
Acreq=np.where(Mu&lt;Mur,0,"zero")
Acreq=np.where(((Mur&lt;Mu)&amp;(Mu&lt;Mumax)),45,Acreq)
Acreq=np.where(Mu&gt;Mumax,60,Acreq)
Print(Acreq)
['0' '45' '60']
</code></pre>

<p>Starting with this:</p>

<pre><code>Mur    = np.array([200,246,372])*3*5
Mumax  = np.array([1400,600,700])*3*5
Mu     = np.array([100,500,2000])*3*5
Acreq  = np.where(Mu&lt;Mur,0,"zero")
Acreq  = np.where((Mur&lt;Mu)&amp;(Mu&lt;Mumax),45,Acreq)
Acreq  = np.where(Mu&gt;Mumax,60,Acreq)

print(Acreq)

['0' '45' '60']
</code></pre>

<p>Try this:</p>

<pre><code>conditions  = [Mu&lt;Mur, (Mur&lt;Mu)&amp;(Mu&lt;Mumax), Mu&gt;Mumax ]
choices     = [ 0, 45, 60 ]
Acreq       = np.select(conditions, choices, default='zero')
print(Acreq)


['0' '45' '60']
</code></pre>

<p>This also works: </p>

<pre><code>np.where((Mur&lt;Mu)&amp;(Mu&lt;Mumax),45,np.where(Mu&gt;Mumax,60,np.where(Mu&lt;Mur,0,"zero")))
</code></pre>

python numpy where