What is the best way to test whether an array can be broadcast to a given shape?
The "pythonic" approach of
>>> x = np.ones([2,2,2])
>>> y = np.ones([2,2])
>>> y = np.ones([2,3])
>>> is_broadcastable(x.shape, y.shape)
I really think you guys are over thinking this, why not just keep it simple?
def is_broadcastable(shp1, shp2): for a, b in zip(shp1[::-1], shp2[::-1]): if a == 1 or b == 1 or a == b: pass else: return False return True