Find range of arguments that return the same result for a linear function
<p>Consider the <code>y = round(300000/x**2)</code>. I would like to find the ranges of <code>x</code> that return the same <code>y</code> for <code>100 &lt; x &lt; 40000</code>.</p>

<p>How would I do that with python/numpy?</p>

<p>All values between <code>100</code> and <code>40000</code> return <code>0</code> for <code>y = round(300/x**2)</code>.</p>

<p>I assume you meant the following</p>

<pre><code>def y(x):
    return round((300/x)**2)
</code></pre>

<p>In which case you can use <a href="https://docs.python.org/3.6/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a></p>

<pre><code>from itertools import groupby
keys, groups = groupby(range(100, 40000), y)
</code></pre>

<p>Now <code>groups</code> will contain grouped integers that result in the same output from the function <code>y</code>.</p>

python numpy