diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-01-06 10:14:10 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-01-06 10:14:10 +0000 |
commit | 6315c4c27eaeca7f2080ea585b1901e2b683b3ff (patch) | |
tree | 2777bf768a4fb125ad3ceb1940f46f70ad4e2d51 /numpy/core/defmatrix.py | |
parent | 5f5c4b92573a060d20cf9bbf70db00d45cda7268 (diff) | |
download | numpy-6315c4c27eaeca7f2080ea585b1901e2b683b3ff.tar.gz |
Added new feature to .view method so that if the argument is a sub-type of the ndarray, an object is returned with all the information of the array.
Diffstat (limited to 'numpy/core/defmatrix.py')
-rw-r--r-- | numpy/core/defmatrix.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/numpy/core/defmatrix.py b/numpy/core/defmatrix.py index a3f161384..9eb8e0011 100644 --- a/numpy/core/defmatrix.py +++ b/numpy/core/defmatrix.py @@ -62,16 +62,19 @@ class matrix(N.ndarray): return data return data.astype(dtype) - if dtype is None: - if isinstance(data, N.ndarray): - dtype = data.dtype - intype = N.obj2dtype(dtype) + if isinstance(data, N.ndarray): + intype = N.dtypedescr(dtype) + new = data.view(matrix) + if intype != data.dtypedescr: + return new.astype(intype) + if copy: return new.copy() + else: return new if isinstance(data, types.StringType): data = _convert_from_string(data) # now convert data to an array - arr = N.array(data, dtype=intype, copy=copy) + arr = N.array(data, dtype=dtype, copy=copy) ndim = arr.ndim shape = arr.shape if (ndim > 2): |