JuliaLang/julia — pull request #2247 by GunnarFarneback (2013-02-09 17:22:05+00:00)
Title: RFC: Linear indexing with multidimensional index.

This change makes array indexing more general and since indexing is automatically controversial, let's start the discussion.

Today indexing a[b], when a is an array and b is an array with more than 1 dimension, gives a no method error for check_bounds. In contrast Matlab produces an array of the same shape as b, or effectively reshape(a[b[:]], size(b)). I've found this indexing quite handy, especially in situations like
img_lut = lut[1 + img]
to apply a lookup table transformation to an image or
I = [1 4 5; 4 2 6; 5 6 3]
A = a[I]
to produce matrices with certain structures.

For indexing with multiple indices, e.g. a[b, c], this patch effectively gives a[b[:], c[:]]. When b and c are row or column vectors this is very reasonable. When they are full matrices it's arguable but happens to be consistent with Matlab.