I want to build an array of points where each row depends on the corresponding row of a timestep array as in:
steps = 5
output = np.empty((steps, 3))
timesteps = np.linspace(0, 1, steps)
for i, step in enumerate(timesteps):
output[i] = [sin(step), cos(step), 0]
With the expected output:
[[0. 1. 0. ]
[0.24740396 0.96891242 0. ]
[0.47942554 0.87758256 0. ]
[0.68163876 0.73168887 0. ]
[0.84147098 0.54030231 0. ]]
How can I vectorize this operation?
I could assign each column independently like so:
out[:, 0] = np.sin(timesteps)
out[:, 1] = np.cos(timesteps)
out[:, 2] = 0
But I'd like to maintain a row-based approach for readability, if possible.
I was thinking of something like
output[:] = [np.sin(timesteps[:]), np.cos(timestep[:]), 0]
but obviously that doesn't work due to setting an array element with a sequence.