Biophysics Biophysics - 5 months ago 15
Python Question

Defining 500 intial random positions of an rotating object in 2-D by Python

I have edited my question. Now I don't want to use loop in my function. The function is for defining initial position of an rotating object in 2-D. I would like to get the output format like this:

theta1 theta2 theta3
phi1 phi2 phi3
eta1 eta2 eta3

The definition of e inside the function must be something else (my opinion). Can anyone help me to get my desired output?

def randposi(N=500):
theta = 2*pi* rand()-pi
phi = arccos(1-2* rand())
eta = 2*pi*rand()-pi
r = random.rand(N)
e = 3*r*array()
return e


What about using a random numpy array ?

Something like that:

import numpy as np
#we create a random array 3xN
r = np.random.rand(3,N) 
#tetha is row 0, phi row 1, eta row 2
#we apply some treatment to get the right range
r[0]=2*np.pi*r[0] -np.pi
r[1]=np.arccos(2*r[1] -1) 
r[2]=2*np.pi*r[2] -np.pi