I am trying to figure out the easiest way to do the equivalent of the following numpy code:
import numpy as np M = np.arange(16).reshape(4, 4) M[:,[1, 3]] >>array([[ 1, 3], [ 5, 7], [ 9, 11], [13, 15]])
I am fine with the slicing result being a new allocation, rather than a view into the original M, but I would like to avoid additional allocations on top of that. Of course, it is possible to create such a submatrix using from_columns or from_fn. The former however requires that I do intermediate allocations (creating a Vec of columns, just so that I can fulfill the &[Column] type requirement) and from_fn feels very unergonomic in this case. Is there a better way?
PS After some thought I figure that an additional allocation is also necessary in the numpy example, since the index array is dynamic. At which point it becomes almost equivalent with from_columns. I am still posting this because I may get some good insights.