I'd like to repeat an array along multiple dimensions, such that it matches the dimensions of another array.
For example, lets put:
import numpy as np
a = np.arange(300)
b = np.zeros((300, 10, 20, 40, 50))
I'd like to expand a such that it matches the dimensions of b, considering than be can have an arbitrary number of dimensions of arbitrary length.
For now, the only thing I can do is a loop over the dimensions like:
c = np.copy(a)
for axis, length in enumerate(b.shape[1:]):
c = np.repeat(c[..., None], length, axis + 1)
But it is rather inefficient for a large number of dimensions ...
np.tilecan do it, but it too does repeatedrepeats. But does it need to fully match, or isbroadcastingenough? There is also abroadcast_to.