Getting linear indices from two vectors containing x and y components of Cartesian coordinates (sub2ind versus LinearIndices())

A long discussion about this:

where the upshot (as I read it) is: If you really need linear indices, you can get them with:

ind2subv(shape, indices) = Tuple.(CartesianIndices(shape)[indices])
sub2indv(shape, indices) = LinearIndices(shape)[CartesianIndex.(indices)]

One question is, though, why do you need linear indices?

1 Like