[SciPy-user] Vector indexing
Robert Kern
robert.kern at gmail.com
Sun Jun 4 20:17:39 EDT 2006
David Grant wrote:
> Vector indexing question:
>
> a=rand(10,10)
>
> 1) a[0:3, 0:3] #gives me the first 3 rows and columns
>
> 2) a[range(2),range(2)] gives me a one-dimensional array of elements [0,0],
> [1,1], [2,2]
Actually, it gets you array([a[0,0], a[1,1]]).
> How do I do 1) using some on-the-fly generated array?
Slice objects.
>>> a[slice(0, 3), slice(0, 3)]
array([[ 0.83840663, 0.36944056, 0.48230632],
[ 0.04508558, 0.25772124, 0.62787961],
[ 0.0455162 , 0.69427227, 0.26374691]])
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the SciPy-User
mailing list