← Back to context

Comment by thaumasiotes

10 hours ago

Well, based on the document complained about in the post...

> The broadcasting mechanism permits index arrays to be combined with scalars for other indices. The effect is that the scalar value is used for all the corresponding values of the index arrays

Because you're using advanced indexing in the second example, 0 is an array of shape 2, [0, 0], not a scalar value.

So the first thing that happens is that you select two coordinates in `array`, those being (1) where i=0 and k=0, and (2) where i=0 and k=1.

Then,

> In general, the shape of the resultant array will be the concatenation of the shape of the index array (or the shape that all the index arrays were broadcast to) with the shape of any unused dimensions (those not indexed) in the array being indexed.

You didn't use the j dimension. The value at each of the two coordinates you selected is a size 20 array, so your result is an array with two rows, those being the two arrays you pointed to.

----

Your example appears to be identical to indexing example D from the article. Example C looks harder to explain.