summaryrefslogtreecommitdiff
path: root/scipy/base/numeric.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2005-09-20 03:00:26 +0000
committerTravis Oliphant <oliphant@enthought.com>2005-09-20 03:00:26 +0000
commit70edf5c9acbc231c9ce9078942fe210d8888305a (patch)
treec0d79497810a81e82f525684be015ec908894cd8 /scipy/base/numeric.py
parent2d0b625d58a48525ded47c4d184ad3837e71c316 (diff)
downloadnumpy-70edf5c9acbc231c9ce9078942fe210d8888305a.tar.gz
Making more consistent.
Diffstat (limited to 'scipy/base/numeric.py')
-rw-r--r--scipy/base/numeric.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/scipy/base/numeric.py b/scipy/base/numeric.py
index e128e1b6a..eb3bf8f1c 100644
--- a/scipy/base/numeric.py
+++ b/scipy/base/numeric.py
@@ -32,6 +32,25 @@ def asarray(a, dtype=None):
"""
return array(a, dtype, copy=0)
+def ensure_array(a, dtype=None):
+ """ensure_array(a, dtype=None) always returns an actual ndarray object.
+ No copy is performed if a is already an array.
+ Meant primarily for debugging.
+ """
+ # exact check
+ while 1:
+ if type(a) is ndarray:
+ return a
+ try:
+ if dtype is None:
+ return a.__array__()
+ else:
+ return a.__array__(dtype)
+ except AttributeError:
+ a = array(a,dtype,copy=1) # copy irrelevant
+ dtype = None
+
+
_mode_from_name_dict = {'v': 0,
's' : 1,
'f' : 2}