[PYTHON MATRIX-SIG] strange slice behaviour
tim@lassi.ece.uiuc.edu
tim@lassi.ece.uiuc.edu
Wed, 24 Apr 1996 16:54:13 -0500
I just recently subscribed to the matrix-sig, so I appologize if this
has gone over allready (I've tried to look over the archive, but its
rather large.) Thanks to everyone for putting Numerical Python
together - it looks great.
I have a 2D array and I slice it, it works fine for non-zero length
slices, but behaves strangely (IMHO) for zero length slices. It works
fine for 1D arrays though...
>>> from Numeric import *
>>> a = array([[1,2,3],[4,5,6],[7,8,9]])
>>> a
1 2 3
4 5 6
7 8 9
>>> a[0:2,1] # OK
2 5
>>> a[0:1,1] # OK
2
>>>>>> a[0:0,1] # This is strange !!!
2 5 8
>>> b = array([1,2,3])
>>> b
1 2 3
>>> b[0:0] # Oops this breaks the PrettyPrinter
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python/numeric/PrettyPrinter.py", line 28, in
arrayToString
max_str_len = max(len(str(maximum.reduce(data))),
ArrayError: can't take anything from an empty array
>>>
>>> b[0:0].shape # This gives what I'd expect.
(0,)
Is this the expected behaviour? If it is, does anyone know of a nice
workaround to get the behaviour I'd expect (i.e., a zero size matrix)?
Thanks,
--
-tim
+--------------------------------------------------------------------+
| Tim Hochberg Ultrahigh Speed Digital Electronics Lab |
| tim@lassi.ece.uiuc.edu University of Illinois |
| http://dogbert.ece.uiuc.edu/~tim (217) 333-6014 |
+--------------------------------------------------------------------+
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================