I have made a function that performs a random walk simulation (random_path
) and returns a 1D array (of length num_steps +1
). I would like to perform a large number of simulations (n_sims
) using this function and then examine my results. I can do this using lists and for loops as:
simulations = []
for i in range(0, n_sims):
current_sim = random_path(x, y, sigma, T, num_steps)
simulations.append(current_sim)
This works fine. I am wondering if there is a more pythonic way of doing this though? Is it possible to do this using only numpy arrays? That is, instead of setting up simulations
as an empty list and then creating a list of arrays with a for loop, can I directly initialise simulations
using the function random_path
to create an array that I guess ultimately would be of shape (n_sims, num_steps + 1)
?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…