I have a matrix which only contains 0 or 1. I also have a list of colors e.g. the below
class_colors = [[0,0,0], [0,255,0]]
m = np.random.random_integers(0,1,(5,5))
e.g. the m
looks like:
0,1,0,1
0,1,0,1
0,1,0,1
How can I replace the 1-values in m
with the class_colors[1]
and
0-values in m
with class_colors[0]
, so the m
will look something like:
[0,0,0], [0,255,0],[0,0,0], [0,255,0]
[0,0,0], [0,255,0],[0,0,0], [0,255,0]
[0,0,0], [0,255,0],[0,0,0], [0,255,0]
I used to be able to do so with np.argmax()
and np.take()
but it requires the m
looks like [class_num,w,h]
and then I can do argmax with axis=0
.
I know I could do it with for loop, but is there any better and faster approach to do this?