[Matrix-SIG] Background for test in NumPy?
Konrad Hinsen
hinsen@ibs.ibs.fr
Tue, 12 May 1998 13:51:50 +0200
> I was making NumPy-1.2 to go with Python-1.5.1 and to include a few small
> improvements. When I ran the "test_all.py" test it failed on the line that
> computes b[10:, :]. In this problem b is a 4 x 4 matrix so the intention is
> evidently to test some strange end case. In fact, the previous "problem" is
> b(10:), which returns zeros((0,4),'l'). (?)
>
> This section of the test is labeled "from Carlos".
>
> In my somewhat humble opinion both of these should have been "Index Error".
> Obviously, I'm not in the "in" group. Can someone fill me in?
The Python rules for slicing sequences are somewhat surprising here.
Slicing *never* returns an IndexError. It returns a new sequence whose
elements are defined by the intersection of what is available and what
is asked for. For out of range indices, it therefore returns an empty
sequence. So zeros((0,4)) is the correct return value in this case,
both for b[10:] and b[10:,:].
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale | Fax: +33-4.76.88.54.94
41, av. des Martyrs | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France | Nederlands/Francais
-------------------------------------------------------------------------------