Reputation: 1757
I have a three channel matrix and I want to place the value which is less than 27
a=numpy.arange(27).reshape(3,3,3)
a[a<27]=0
However, If I want to replace only on first channel, the way I can do is to write a for loop
for i in range(3):
for j in range(3):
if a[i][j][0] < 27:
a[i][j][0]=0
I am not sure how to do this with a more simple way.
thank you
Upvotes: 0
Views: 54
Reputation: 293
You can try with:
a=numpy.arange(27).reshape(3,3,3)
a[a[:,:,0]<27, 0]=0
Upvotes: 1