diff options
author | Travis Oliphant <oliphant@enthought.com> | 2005-10-13 23:39:44 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2005-10-13 23:39:44 +0000 |
commit | 2c6e233984b6af96d3bf3a38b4932aa5f4c433ad (patch) | |
tree | 0efb687e0a496844cc3cd8511d64f007c77e4ea1 /scipy/base/numeric.py | |
parent | 4d9e46d48de3ce4039ce5ebe5433eab339067b98 (diff) | |
download | numpy-2c6e233984b6af96d3bf3a38b4932aa5f4c433ad.tar.gz |
Fixed so that array always returns an array object.
Diffstat (limited to 'scipy/base/numeric.py')
-rw-r--r-- | scipy/base/numeric.py | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/scipy/base/numeric.py b/scipy/base/numeric.py index 931a6cfff..77edcdf99 100644 --- a/scipy/base/numeric.py +++ b/scipy/base/numeric.py @@ -27,35 +27,17 @@ fastCopyAndTranspose = multiarray._fastCopyAndTranspose register_dtype = multiarray.register_dtype can_cast = multiarray.can_cast - def asarray(a, dtype=None): """asarray(a,dtype=None) returns a as an array. Unlike array(), - no copy is performed if a is already an array. Will return a subclass - of array. + no copy is performed if a is already an array. Subclasses are converted + to base class ndarray. """ return array(a, dtype, copy=0) -def asndarray(a, dtype=None): - """asndarray(a, dtype=None) always returns an actual ndarray object. - No copy is performed if a is already an array. - Meant primarily for debugging. +def asanyarray(a, dtype=None): + """will pass subclasses through... """ - dtype = obj2dtype(dtype) - # exact check - while 1: - if type(a) is ndarray: - if dtype is None or a.dtype is dtype: - return a - else: - return a.astype(dtype) - try: - if dtype is None: - return a.__array__() - else: - return a.__array__(dtype) - except AttributeError: - a = array(a,dtype) # copy irrelevant - dtype = None + return array(a, dtype, copy=0, subok=1) def isfortran(a): return a.flags['FNC'] @@ -66,9 +48,9 @@ def zeros_like(a): If you don't explicitly need the array to be zeroed, you should instead use empty_like(), which is faster as it only allocates memory.""" - - a = asarray(a) - return zeros(a.shape,a.dtype, a.flags['FNC']) + + a = asanyarray(a) + return a.__array_wrap__(zeros(a.shape,a.dtype, a.flags['FNC'])) def empty_like(a): """Return an empty (uninitialized) array of the shape and typecode of a. @@ -77,8 +59,8 @@ def empty_like(a): your array to be initialized, you should use zeros_like(). """ - a = asarray(a) - return empty(a.shape,a.dtype, a.flags['FNC']) + a = asanyarray(a) + return a.__array_wrap__(empty(a.shape,a.dtype, a.flags['FNC'])) # end Fernando's utilities |