I have some code where I repeatedly need to repeatedly broadcast arrays in complex ways, for example:
a = b[np.newaxis, ..., :, np.newaxis] * c[..., np.newaxis, np.newaxis, :]
Is there an object to which I can store these slicing specifications?
i.e. (but obviously this doesn't work):
s1 = magic([np.newaxis, ..., :, np.newaxis])
s2 = magic([..., np.newaxis, np.newaxis, :])
Edit: perhaps this could be done with numpy.broadcast_to
, but it's unclear how exactly while making sure that the correct axes are broadcast over...