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>Convert your array to a numpy array (<code>numpy.asarray</code>) then to replace the values you would use the following:</p>

<pre><code>import numpy as np
N = np.asarray(N)

N[N &gt; 10] = 0
</code></pre>

<p><a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.asarray.html" rel="nofollow">numpy.asarray documentation</a></p>

python arrays