def reduce_along_dim(img, dim, weights, indicies):
 other_dim = abs((dim - 1))
 if (other_dim == 0):
  weights = np.tile(weights[np.newaxis, :, :, np.newaxis], (img.shape[other_dim], 1, 1, 3))
  out_img = (img[:, indicies, :] * weights)
  out_img = np.sum(out_img, axis=2)
 else:
  weights = np.tile(weights[:, :, np.newaxis, np.newaxis], (1, 1, img.shape[other_dim], 3))
  out_img = (img[indicies, :, :] * weights)
  out_img = np.sum(out_img, axis=1)
 return out_img

def reduce_along_dim ( img , dim , weights , indicies ) : other_dim = abs ( ( dim - 1 ) ) if ( other_dim == 0 ) : weights = np . tile ( weights [ np . newaxis , : , : , np . newaxis ] , ( img . shape [ other_dim ] , 1 , 1 , 3 ) ) out_img = ( img [ : , indicies , : ] * weights ) out_img = np . sum ( out_img , axis = 2 ) else : weights = np . tile ( weights [ : , : , np . newaxis , np . newaxis ] , ( 1 , 1 , img . shape [ other_dim ] , 3 ) ) out_img = ( img [ indicies , : , : ] * weights ) out_img = np . sum ( out_img , axis = 1 ) return out_img
perform bilinear interpolation given along the image dimension dim -weights are the kernel weights -indicies are the crossponding indicies location return img resize along dimension dim .