diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-02-24 10:48:35 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-02-24 10:48:35 +0000 |
commit | 24a8d329deff1e63c40460fe41f72dc420ade1c9 (patch) | |
tree | 4b8426eb59a4c926b1613708eb1e37a1b1a6df04 /numpy/core/defmatrix.py | |
parent | 8db604ba730d0d64b6491cee731ef363d459207f (diff) | |
download | numpy-24a8d329deff1e63c40460fe41f72dc420ade1c9.tar.gz |
Don't allow matrices larger than ndim=2
Diffstat (limited to 'numpy/core/defmatrix.py')
-rw-r--r-- | numpy/core/defmatrix.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/numpy/core/defmatrix.py b/numpy/core/defmatrix.py index 9234d2f53..65339793a 100644 --- a/numpy/core/defmatrix.py +++ b/numpy/core/defmatrix.py @@ -101,6 +101,13 @@ class matrix(N.ndarray): def __array_finalize__(self, obj): ndim = self.ndim + if (ndim > 2): + newshape = tuple([x for x in self.shape if x > 1]) + ndim = len(newshape) + if ndim == 2: + self.shape = newshape + elif (ndim > 2): + raise ValueError, "shape too large to be a matrix." if ndim == 0: self.shape = (1,1) elif ndim == 1: |