<p dir="auto">Hi everyone :)</p>
<p dir="auto">I found a small inaccuracy in the docs for np.clip. There it says</p>
<blockquote>
<p dir="auto">Equivalent to but faster than <code class="notranslate">np.maximum(a_min, np.minimum(a, a_max))</code><br>
<a href="https://github.com/numpy/numpy/blob/master/numpy/core/fromnumeric.py#L2039-L2051">https://github.com/numpy/numpy/blob/master/numpy/core/fromnumeric.py#L2039-L2051</a></p>
</blockquote>
<p dir="auto">but the function actually seems to behave like <code class="notranslate">np.minimum(a_max, np.maximum(a, a_min))</code></p>
<p dir="auto">To be fair: This is only relevant if the user mixes up the order of the inputs.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np

def min_max(a, a_min, a_max):
    return np.minimum(a_max, np.maximum(a, a_min))

def max_min(a, a_min, a_max):
    return np.maximum(a_min, np.minimum(a, a_max))

print(np.clip(4, 5, 2))   # Returns 2
print(min_max(4, 5, 2))   # Returns 2
print(max_min(4, 5, 2))   # Returns 5"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-k">def</span> <span class="pl-en">min_max</span>(<span class="pl-s1">a</span>, <span class="pl-s1">a_min</span>, <span class="pl-s1">a_max</span>):
    <span class="pl-k">return</span> <span class="pl-s1">np</span>.<span class="pl-en">minimum</span>(<span class="pl-s1">a_max</span>, <span class="pl-s1">np</span>.<span class="pl-en">maximum</span>(<span class="pl-s1">a</span>, <span class="pl-s1">a_min</span>))

<span class="pl-k">def</span> <span class="pl-en">max_min</span>(<span class="pl-s1">a</span>, <span class="pl-s1">a_min</span>, <span class="pl-s1">a_max</span>):
    <span class="pl-k">return</span> <span class="pl-s1">np</span>.<span class="pl-en">maximum</span>(<span class="pl-s1">a_min</span>, <span class="pl-s1">np</span>.<span class="pl-en">minimum</span>(<span class="pl-s1">a</span>, <span class="pl-s1">a_max</span>))

<span class="pl-en">print</span>(<span class="pl-s1">np</span>.<span class="pl-en">clip</span>(<span class="pl-c1">4</span>, <span class="pl-c1">5</span>, <span class="pl-c1">2</span>))   <span class="pl-c"># Returns 2</span>
<span class="pl-en">print</span>(<span class="pl-en">min_max</span>(<span class="pl-c1">4</span>, <span class="pl-c1">5</span>, <span class="pl-c1">2</span>))   <span class="pl-c"># Returns 2</span>
<span class="pl-en">print</span>(<span class="pl-en">max_min</span>(<span class="pl-c1">4</span>, <span class="pl-c1">5</span>, <span class="pl-c1">2</span>))   <span class="pl-c"># Returns 5</span></pre></div>
<p dir="auto">It's sometimes hard to tell in numpy whether a given numpy function will also be a method of an array.</p>
<p dir="auto">e.g. You can go <code class="notranslate">arr.max()</code> or <code class="notranslate">np.max(arr)</code>, but you can's go <code class="notranslate">arr.abs()</code> (you need to go <code class="notranslate">np.abs(arr)</code>.</p>
<p dir="auto">Same goes for most functions: <code class="notranslate">median</code>, <code class="notranslate">sign</code>, <code class="notranslate">exp</code>, etc.  It would be nice, because I find it much more readable to look at:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="mean_rmse = ((out-targ)**2).mean(axis=1).sqrt().mean(axis=0)"><pre class="notranslate"><code class="notranslate">mean_rmse = ((out-targ)**2).mean(axis=1).sqrt().mean(axis=0)
</code></pre></div>
<p dir="auto">Than:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="mean_rmse = np.mean(np.sqrt(np.mean((out-targ)**2, axis =1)), axis=0)"><pre class="notranslate"><code class="notranslate">mean_rmse = np.mean(np.sqrt(np.mean((out-targ)**2, axis =1)), axis=0)
</code></pre></div>