Is there a way to slice the array below without having to define the row indices i.e. not having to write range(len(X))?
X = np.arange(10*2).reshape((10,2))
L = np.random.randint(0,2,10)
Xs = X[range(len(X)),L]
I thought it was possible to slice with X[:,L] but looks like it's not.
linspacetakes two arguments minimum: start and end. So your code doesn't run. Is your NumPy different? What version? Also,X[:,L]does work for me, provided that I dolinspace(5, 20, 10*2)or so.np.arange()instead ofrange(). docs.scipy.org/doc/numpy/user/…Lhas shape(10,), but you're using it to index the dimension ofXthat has length 2, not the length 10 one. Is that intentional?