Q:

Vectorized arange using np.einsum for raycast

I have a D dimensional point and vector, p and v, respectively, a positive number n, and a resolution.
I want to get all points after successively adding vector v*resolution to point p n/resolution times.
Example
p = np.array([3, 5])
v = np.array([-1.5, 3])
n = 10
resolution = 1.5

result:
[[  3.  ,   5.  ],
 [  0.75,   9.5 ],
 [ -1.5 ,  14.  ],
 [ -3.75,  18.5 ],
 [ -6.  ,  23.  ],
 [ -8.25,  27.5 ],
 [-10.5 ,  32.  ]]

My current approach is to tile the range, given by n and the resolution, by the dimension D, multiply by that by v and add p.
def getPoints(p, v, n, resolution=1.):
    dRange = np.tile(np.arange(0, n, resolution), (v.shape[0],1))

    return np.multiply(v.reshape(-1,1), dRange).T + p

Is there is a direct way to calculate DRange using np.einsum or another method?

A:

Approach #1
Here's one approach leveraging NumPy broadcasting -
np.arange(0, n, resolution)[:,None] * v + p

Basically, we extend the range array to 2D, keeping the second one as singleton, to let it broadcast for elementwise multiplication against 1D v, giving us a 2D array. Then, we add p to it.
Approach #2
There isn't any sum-reduction here, so np.einsum or any dot-based function even though should work, but won't lend any help on performance. Let's put it out anyway, as it was mentioned in the question -
np.einsum('i,j->ij',np.arange(0, n, resolution), v) + p

