code: def pack_rgb(rgb):
  
      '''Packs a 24-bit RGB triples into a single integer,
  works on both arrays and tuples.'''
  
      orig_shape = None
  
      if isinstance(rgb, np.ndarray):
          assert rgb.shape[-1] == 3
          orig_shape = rgb.shape[:-1]
      else:
          assert len(rgb) == 3
          rgb = np.array(rgb)
  
      rgb = rgb.astype(int).reshape((-1, 3))
  
      packed = (rgb[:, 0] << 16 |
                rgb[:, 1] << 8 |
                rgb[:, 2])
  
      if orig_shape is None:
          return packed
      else:
          return packed.reshape(orig_shapef pack_rgb(rgb):
  
      '''Packs a 24-bit RGB triples into a single integer,
  works on both arrays and tuples.'''
  
      orig_shape = None
  
      if isinstance(rgb, np.ndarray):
          assert rgb.shape[-1] == 3
          orig_shape = rgb.shape[:-1]
      else:
          assert len(rgb) == 3
          rgb = np.array(rgb)
  
      rgb = rgb.astype(int).reshape((-1, 3))
  
      packed = (rgb[:, 0] << 16 |
                rgb[:, 1] << 8 |
                rgb[:, 2])
  
      if orig_shape is None:
          return packed
      else:
          return packed.reshape(orig_shape)
docs: Packs a 24-bit RGB triples into a single integer,
  works on both arrays and tuples.