Filter one array according to data in another array
<p>I have two arrays of random numbers, <code>X</code> and <code>Y</code>. X represents x-coordinates and <code>Y</code> represents y-coordinates. I want to filter <code>X</code> such that I only keep indices <code>i</code> of <code>X</code> where:</p>

<pre><code>X[i]^2 + Y[i]^2 &lt; 1
</code></pre>

<p>I know how to filter with values in 1 array but since I need to use 2, I am not sure what to do. I am not allowed to use loops of any kind.</p>

<p>So I think these arrays are too large to loop? If you only want to <strong>keep</strong> the indices for later, try <a href="https://wiki.python.org/moin/Generators" rel="nofollow">Generators</a>:</p>

<pre><code>def X_indices_filterd(X, Y):
    for i in enumerate(X):
        if (X[i] ** 2 + Y[i] ** 2 &lt; 1) yield i
</code></pre>

python arrays numpy