I'd like to create a list of lists of normal distributions with a given beginning mean, sample size, and standard deviation, but where the mean dynamically follows the Arctangent curve over subsequent iterations/lists.
consider:
np.random.normal(5, 1.5, size=(52, 400))
array([[5.91413507, 6.03442582, 5.13545575, ..., 4.70864259, 4.46786696,
5.907657 ],
[5.96475187, 2.78293757, 6.6995019 , ..., 6.75333878, 4.40617338,
5.78887913],
[2.24474929, 4.86493468, 4.81687713, ..., 4.64654325, 4.52163674,
3.65247517],
...,
[8.26692519, 4.17375668, 6.53084905, ..., 3.52156159, 2.81350621,
5.1208226 ],
[2.1335012 , 3.84207539, 4.5672884 , ..., 5.86160579, 1.59491514,
2.31374464],
[4.28164175, 5.30687236, 3.32682318, ..., 6.54310196, 2.36919655,
6.23774753]])
The above outputs an array of 52 lists with 400 data points per list, mean 5 and and standard deviation 1.5 per each of those 52.
But I'd like to be able to have the mean value only start at 5 and then dynamically increasing following the Arctangent function over those 52 iterations while keeping the sample size and standard deviation constant per each subsequent list.
How can this be done?
CodePudding user response:
The arctan
varies from -pi/2
to pi/2
, so if I understand your correctly, you want the mean vary from say 5
to 5 pi
. If so you can do
mean = 5
sd = 1.5
means = np.arctan(np.linspace(-4, 4, 52)) np.pi/2 mean
a = np.random.normal(means, sd, size=(400, 52)).T
This gives you an array of 52 rows with 400 columns, the mean of the rows starts from 5
in row 0 and increases acording to an arctan function to 5 pi
in row 51. The standard deviation of each row is 1.5
.