I have a 3-D array with shape [1080, 1920, 4], the last axis stands for RGBA channels of a picture, and I have a dict mapping from RGBA values to int, I want to use np.vectorize to convert this array to a 2-D array with shape [1080, 1920], how can I pass the array as a 2-D array with last dimension is a list to the vectorized function?
array = [[[112, 25, 235, 255],
[112, 25, 235, 255],
[112, 25, 235, 255],
...,
[ 35, 35, 30, 255],
[ 41, 40, 37, 255],
[ 39, 41, 37, 255]]
...,
[ 35, 35, 30, 255],
[ 41, 40, 37, 255],
[ 39, 41, 37, 255]]]
dic = {(35, 35, 30, 255): 1, (41, 40, 37, 255): 2}
np.vectorize(lambda x: dic.get(tuple(x)))()
what should I pass into the last ()
np.vectorizeis a glorifiedforloop. Are you open to other methods?array.reshape(-1, 4).