I try to do a random walk for n particles in three dimensions. To do so I created an array with random initial data with n times 3 entries. Then I created a function that adds a random number between -5 and 5 to each of these entries. The problem I'm trying to solve now is that I have to iterate this T times and add the arrays of each time frame along a new axis. But I don't know how to get this done, I tried stack, apply_over_axis, concatenate, etc. How do I get this (n,3,T) array?
This is the code that I have so far (and works as I want it to)
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
rng = np.random.default_rng(12345)
n=100 #number of particles
T=300 #amount of time frames
#create (n,3) array of random initial data
init = np.array([rng.uniform(100) for i in range(n*3)])
init = init.reshape(n,3)
#one random step in each entry
def randomstep(init):
for i in range(n):
for j in range(3):
init[i,j] = init[i,j]+ rng.uniform(-5,5)
return init
For getting the values along the "time axis" I tried e.g. the following, but I only get errors.
def tframes(T,init):
for i in range(T):
init = np.stack((init,randomstep(init)))
return init
I would be extremely thankful if someone could help me!:)
Aucun commentaire:
Enregistrer un commentaire