Find values in array and change them efficiently
<p>I am working with a large array with around 300 000 values. It has 100 000 rows and 3 columns. I am doing iterations with this array and if any value in the first column exceeds a limit of lets say 10, I want the number to be replaced. Is there any more efficient way than running something like this?:</p>

<pre><code>for i in range(N):
    if array[i][0]&gt;10:
        array[i][0] = 0 
</code></pre>

<p>I need to repeat this sequense for the other two columns as well which included with all my other iterations makes my code pretty slow.</p>

<p>If I understand you correctly you`re looking for something like that:</p>

<pre><code>&gt;&gt;&gt; from numpy import array
&gt;&gt;&gt; a = array([[1,2,3],[4,5,6],[7,8,9]])
&gt;&gt;&gt; a
array([[1, 2, 3],
       [4, 5, 6],
       [7, 8, 9]])
&gt;&gt;&gt; a[a&gt;5]=10       # &lt;--- here the "magic" happens
&gt;&gt;&gt; a
array([[ 1,  2,  3],
       [ 4,  5, 10],
       [10, 10, 10]])
</code></pre>

python arrays