Is there a convenient way to apply a lookup table to a large array in numpy?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I’ve got an image read into numpy with quite a few pixels in my resulting array. I calculated a lookup table with 256 values. Now I want to do the following: for i in image.rows: for j in image.cols: mapped_image[i,j] = lut[image[i,j]] Yep, that’s basically what a lut does. Only problem is: I want to do it efficient and calling that loop in python will have me waiting for some seconds for it to finish. I know of numpy.vectorize() , it’s simply a convenience function that calls the same python code. 回答1: You can just use image to index into