title: Is there a significant overhead in calling `np.asarray' on a NumPy array?
body: <p>I am quite new to the Python world, so please excuse my dumb question.</p>
  
  <p>In a number of circumstances, I implement a functions that works on array-like numerical inputs, and it is usually advantageous to make use of NumPy utilities for basic operations on the sequences.  To this end, I would write something like this:</p>
  
  <pre><code>import numpy as np
  
  def f(x):
      if not isinstance(x, np.ndarray):
          x = np.asarray(x)
      # and from now on we know that x is a NumPy array, with all standard methods
  </code></pre>
  
  <p>(Note that I don't want to rely on the caller to always pass NumPy arrays.)</p>
  
  <p>I was wondering what would be the additional overhead if simplified the code by removing the <code>if</code>?  I.e., having something like</p>
  
  <pre><code>def f(x):
      x = np.asarray(x)
      # and from now on we know that x is a NumPy array, with all standard methods
  </code></pre>
  
  <p>Basically, the difference between two cases is that second code is more compact, but will unnecessarily call <code>np.asarray</code> even if <code>x</code> is already a NumPy array.</p>