numpyの置換にはFancy Indexingを使うのが効率的です。 参考 Python Data Science Handbook [Fancy Indexing][1] import numpy as np img = np.array([ [0, 1, 2], [2, 1, 1], ]) ind = np.array([np.array([255, 0, 0]), np.array([125, 125, 0]), np.array([0, 125, 125])]) ind[img] [1]: https://jakevdp.github.io/PythonDataScienceHandbook/02.07-fancy-indexing.html