[PYTHON MATRIX-SIG] Slice expressions

Konrad Hinsen hinsen@ibs.ibs.fr
Thu, 17 Oct 96 10:14:13 +0100


> 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),)

Unfortunately there is no way to remove that restriction completely.
I could make standard slices work for the case where both indices
are specified (by implementing __getslice__ and a dummy __len__ that
always returns zero), but you'd get a wrong answer if you leave out
the second index (which would then be set to zero). You could
obtain the correct result if __len__ could return None, but it must
return a non-negative integer...

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------

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

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