I have a feature map that needs to be divied with another 2d constant, the feature map has shape [H, W, ...] , the 2d constant has shape [H, W] , however when I use np.divide it says these two tensor can not be broadcast to a common shape: import numpy as np a = np.random.rand(4, 3 ,3) b = np.random.rand(4, 3) c = np.divide(a, b, where=b > 0) as the numpy broadcast rules say b will be broadcast to shape [1, 4, 3] instead of [4, 3, 1] , thus I can't do this operation with boradcast. I would like to divide my feature map with that constant tensor where the constant is not 0 to avoid zero-div error, what should I do ? Continue reading...