title: How to turn 3d array into 2d array with labels based on the 3rd dimension?
body: <p>I have a 3D NumPy Array with dimensions (224, 224, 3). The third dimension represents colors. I have only 21 colors in the whole picture so there are only 21 distinct values for each pixel.
  <br>These are the color codes:</p>
  <pre><code>colors = np.array([
                    [  0,   0,   0], [128,   0,   0], [  0, 128,   0], [128, 128,   0], [  0,   0, 128],
                    [128,   0, 128], [  0, 128, 128], [128, 128, 128], [ 64,   0,   0], [192,   0,   0],
                    [ 64, 128,   0], [192, 128,   0], [ 64,   0, 128], [192,   0, 128], [ 64, 128, 128],
                    [192, 128, 128], [  0,  64,   0], [128,  64,   0], [  0, 192,   0], [128, 192,   0],
                    [ 0, 64, 128]], dtype=np.uint8)
  </code></pre>
  <p>How can I iterate over each pixel and create a 2D array with shape (224, 224) which consists of integers 0 to 20 based on the value of 3rd dimension? What would be the most efficient way to do this?</p>