Given a numpy array x of shape (m,) and a numpy array y of shape (m/n,), how do I multiply x by corresponding elements of y efficiently?
Here's my best attempt:
In [13]: x = np.array([1, 5, 3, 2, 9, 1])
In [14]: y = np.array([2, 4, 6])
In [15]: n = 2
In [16]: (y[:, np.newaxis] * x.reshape((-1, n))).flatten()
Out[16]: array([ 2, 10, 12, 8, 54, 6])