[SciPy-user] "dynamic" indexing

Zunbeltz zunbeltz at lcdx00.wm.lc.ehu.es
Thu Jun 10 01:18:19 CDT 2004

On Wed, 9 Jun 2004, Addison, Jason wrote:

> How can I take a slice from an array when I do not know before hand the
> dimension of the source array? For example:

len(slice) gives you the length of the array, so you don't need to know
the length before hand. You also can slice with negative indexes, for
example to get the last element a[-1] and so on.

see http://docs.python.org/lib/typesseq.html on the python
library reference. Arrays all call list in python and the are mutable

> # slice is genereated dynamically, its length is not known before hand
> slice = [(2,4),(1,4),(0,15)]
> # then I'd like to somehow use slice to slice an array
> a[slice] -> a[2:4,1:4,0:15]

You can't use a construct like a[2:4,1:4,0:15].


> Thank you
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user

Zunbeltz Izaola Azkona              (zunbeltz at wm dot lc dot ehu dot es)
Materia Kondentsatuaren Fisika Saila      |
Zientzia eta Teknologia Fakultatea        |   Telf:  34 946015326
Euskal Herriko Unibertsitatea             |
PK 644                                    |   Fax:   34 944648500
48080 Bilbo (SPAIN)                       |

More information about the SciPy-user mailing list