[PYTHON MATRIX-SIG] Slice expressions

Perry A. Stoll pas@lems.brown.edu
Wed, 16 Oct 1996 15:53:36 -0400 (EDT)


I keep making this mistake...can someone put some documentation somewhere
that this index_expression _must_ be indexed with all three numbers to ensure
correct results, which is not the case with an actual array object. 

>>> index_expression[2:-2]                       
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AttributeError: __len__
>>> index_expression[2:-2:1]
(slice(2, -2, 1),)

Thanks,
  -Perry
   <pas@lems.brown.edu>

On Wed, 16 Oct 1996, Konrad Hinsen wrote:

> Just in case someone else needs it, here's the definition that I just
> put into my copy of Core.py:
> 
> ----------------------------------------------------------------------
> class _index_expression_class:
> 
>     def __getitem__(self, item):
>         if type(item) != type(()):
>             return (item,)
>         else:
>             return item
> 
> index_expression = _index_expression_class()
> ----------------------------------------------------------------------

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================