what is the quickest way to determine if an array is sorted?
<p>This may seem like a duplicate of <a href="https://stackoverflow.com/questions/28419877/check-whether-non-index-column-sorted-in-pandas">Check whether non-index column sorted in Pandas</a></p>

<p>I read that post and all the answers.  No one (save one answer) addresses using numpy.  It's all focused on python lists.  By asking a similar question with the <code>numpy</code> tag, I believe I'll get a different class of answers.  That said, on to the question.</p>

<hr>

<p>consider two arrays <code>a</code> and <code>b</code>.  <code>b</code> is sorted while <code>a</code> is not.</p>

<pre><code>a = np.array([2, 1, 3, 0])

b = np.arange(4)
</code></pre>

<p>I've written this function to determine sorted-ness</p>

<pre><code>def is_sorted(x):
    return (np.arange(len(x)) == np.argsort(x)).all()
</code></pre>

<p>What else can I do to improve on this idea?  What is the quickest <code>pandas</code> or <code>numpy</code> algorithm to determine if a <code>pd.Series</code> or <code>np.ndarray</code> is sorted?</p>

<hr>

<pre><code>is_sorted(a)

False  
</code></pre>

<hr>

<pre><code>is_sorted(b)

True  
</code></pre>

<hr>