A tuple as an index of a multidimensional array

I found a very similar question to mine, but not quite the same. This: here However, in ntimes case, the size of the array corresponds to the number of sizes that the tuple points to. In my case, I have a 4-dimensional array and a two-dimensional tuple, like this:

from numpy.random import rand
big_array=rand(3,3,4,5)
tup=(2,2)

I want to use a tuple as an index for the first two dimensions and manually index the last two. Sort of:

big_array[tup,3,2]

However, I get a repetition of the first dimension with index = 2 in the fourth dimension (since it was not technically indexed). This is because this indexing interprets double indexing for the first dimension instead of one value for each dimension,

eg. 
| dim 0:(index 2 AND index 2) , dim 1:(index 3), dim 2:(index 2), dim 3:(no index)|
instead of 
|dim 0(index 2), dim 1(index 2), dim 2:(index 3), dim 3:(index 2)|.

How can I "unzip" this tuple? Any ideas? thank!

+5
2

, , :

from numpy.random import rand
big_array=rand(3,3,4,5)
chosen_slice = (2,2)

>>> big_array[ chosen_slice ]
array([[ 0.96281602,  0.38296561,  0.59362615,  0.74032818,  0.88169483],
       [ 0.54893771,  0.33640089,  0.53352849,  0.75534718,  0.38815883],
       [ 0.85247424,  0.9441886 ,  0.74682007,  0.87371017,  0.68644639],
       [ 0.52858188,  0.74717948,  0.76120181,  0.08314177,  0.99557654]])

>>> chosen_part = (1,1)

>>> big_array[ chosen_slice ][ chosen_part ]
0.33640088565877657

, .

+2

numpy:

big_array[tup+(3,2)]

. __getitem__ ( ), __getitem__ . tuple ( , ), numpy , .

+6

All Articles