[Numpy-discussion] prerelease proposal for matrix behavior

Alan G Isaac aisaac@american....
Sat Apr 26 08:46:57 CDT 2008


On Sat, 26 Apr 2008, Bill Baxter apparently wrote:
> Any change to the behavior of x[0] for matrices is going to break a lot of code. 

OK, how about a warning then?
E.g., see attached patch.

Cheers,
Alan

-------------- next part --------------
--- defmatrix.old	Sat Apr 26 09:34:11 2008
+++ defmatrix.py	Sat Apr 26 09:37:13 2008
@@ -1,6 +1,7 @@
 __all__ = ['matrix', 'bmat', 'mat', 'asmatrix']
 
 import sys
+import warnings
 import numeric as N
 from numeric import concatenate, isscalar, binary_repr
 
@@ -119,6 +120,9 @@
         return
 
     def __getitem__(self, index):
+        if isscalar(index):
+            warnings.warn("scalar indexing of matrices is deprecated, use x[i,:] instead",
+                         DeprecationWarning, stacklevel=2)
         self._getitem = True
         try:
             out = N.ndarray.__getitem__(self, index)


More information about the Numpy-discussion mailing list