code: def _as_array(arr, dtype=None):
      
      if arr is None:
          return None
      if isinstance(arr, np.ndarray) and dtype is None:
          return arr
      if isinstance(arr, integer_types + (float,)):
          arr = [arr]
      out = np.asarray(arr)
      if dtype is not None:
          if out.dtype != dtype:
              out = out.astype(dtype)
      if out.dtype not in _ACCEPTED_ARRAY_DTYPES:
          raise ValueError("'arr' seems to have an invalid dtype: "
                           "{0:s}".format(str(out.dtype)))
      return out
docs: Convert an object to a numerical NumPy array.
  
      Avoid a copy if possible.