[Numpy-discussion] array slicing question

Alexander Schmolck a.schmolck at gmx.net
Tue Apr 5 05:28:13 CDT 2005


Gary Ruben <gruben at bigpond.net.au> writes:

> This may be relevant to Numeric 3, but is possibly just a general question
> about array slicing which will either reveal a deficiency in specifying slices
> or in my knowledge of slicing with numpy.
> A while ago I was trying to reimplement some Matlab image processing code in
> Numeric and revealed a deficiency in the way slices are defined. Suppose I
> have an n x m array and want to slice off the first and last p rows and
> columns where p can range from 0 to some number. Matlab provides a clean way
> of doing this, but in numpy it's a bit of a mess.
>
> You might think you could do
>  >>> p=1
>  >>> b = a[p:-p]

b = a[p:-p or None]

'as





More information about the Numpy-discussion mailing list