For example, I have a matrix like this:
In [2]: a = np.arange(12).reshape(3, 4)
In [3]: a
Out[3]:
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
and a starting point index array:
In [4]: idx = np.array([1, 2, 0])
In [5]: idx
Out[5]: array([1, 2, 0])
Are there any vectorized ways to do such things:
for i in range(3):
# The following are some usecases
a[i, idx[i]:] = 0
a[i, idx[i]-1:] = 0
a[i, :idx[i]] = 0
a[i, idx[i]:idx[i]+2] = 0
Edit: expected output:
array([[ 0, x, x, x],
[ 4, 5, x, x],
[ x, x, x, x]])
x is placeholder indicating what I'd like to select.
aas all zeros. Are you looking for something like this?