Category : numpy-random

I’m running python code that’s similar to: import numpy def get_user_group(user, groups): if not user.group_id: user.group_id = assign(groups) return user.group_id def assign(groups): for group in groups: ids.append(group.id) percentages.append(group.percentage) # e.g. .33 assignment = numpy.random.choice(ids, p=percentages) return assignment We are running this in the wild against tens of thousands of users. I’ve noticed that the assignments ..

Read more

I had some code that random-initialized some numpy arrays with: rng = np.random.default_rng(seed=seed) new_vectors = rng.uniform(-1.0, 1.0, target_shape).astype(np.float32) # [-1.0, 1.0) new_vectors /= vector_size And all was working well, all project tests passing. Unfortunately, uniform() returns np.float64, though downstream steps only want np.float32, and in some cases, this array is very large (think millions of ..

Read more

I’m developing a portfolio optimisation code with constraints using monte-carlo simulation. However, I have run into a problem. My problem is as follows: I have a list of instruments ["Multi", "Equity 1", "Equity 2", "Equity 3", "FI", "Cash"] And I would like to generate a list of random numbers for these instruments e.g. weights (random ..

Read more