Reputation: 287
Let f_1
be an array of shape (a,b)
and f_2 an array of shape (2*a,b)
. f_2
equals f_1
if we restrict the array on even rows. I want to set f_2
to zero to everywhere where f_1
is zero. I tried the following:
I = np.argwhere(f_1 == 0)
for x in I:
x[0] = 2*x[0]
f_2[I] = 0
but LA.norm(f_2)
results in 0.0
so this approach apparently doesn't work.
Upvotes: 1
Views: 1135
Reputation: 476614
You can multiply the indices by two for the first dimension with:
i,j = np.where(f_1 == 0)
f_2[2*i,j] = 0
Upvotes: 1
Reputation: 14127
You could use slicing to select even columns and boolean indexing to set zeros.
f_2[::2][f_1==0]=0
Upvotes: 2
Reputation: 681
Why not simply do something like this?
for x in I:
f_2[2*x[0]][x[1]] = 0
Upvotes: 1