Iterate and assign value - Python - Numpy
<p>IÂ´m a newbie in Python.</p>

<p>IÂ´m trying to do something like this. Iterate an array, compare the value with a constant and assign values to another array.</p>

<p><img src="http://i.stack.imgur.com/r0Sqk.jpg" alt="What IÂ´m trying to do"></p>

<p>Thanks in advance!</p>

<p>Regards</p>

<p>Eduardo</p>

<p>The question needs to be more specific BTW look how the element of a numpy <code>array</code> are accessed and modified:</p>

<pre><code>&gt;&gt;&gt; # generating a random numpy array
... np_array = numpy.random.randint(0,100,10)
&gt;&gt;&gt; np_array
45: array([22, 71, 40, 83, 33, 52, 29, 31, 77, 87])
&gt;&gt;&gt; # Replacing 26 with 30
... np_array[np_array == 26] = 30
&gt;&gt;&gt; np_array
46: array([22, 71, 40, 83, 33, 52, 29, 31, 77, 87])
&gt;&gt;&gt; # multiplying all the numbers less than 50 by 10
... np_array[np_array &lt; 50] *= 10
&gt;&gt;&gt; np_array
47: array([220,  71, 400,  83, 330,  52, 290, 310,  77,  87]) 
</code></pre>

<p><a href="http://docs.scipy.org/doc/numpy/user/basics.indexing.html" rel="nofollow">http://docs.scipy.org/doc/numpy/user/basics.indexing.html</a> </p>

python arrays loops numpy