All Questions
1,134 questions
2
votes
3
answers
136
views
how to generate random probability arrays with pre specified mean
I have a pre specified mean [0.5, 0.5, 0]. This is a probability array which sum up to 1.
I want to generate several, say 10 random probability arrays (each sums up to 1) whose mean is [0.5, 0.5, 0], ...
0
votes
0
answers
53
views
Best practice for function-level reproducibility of random number generation with NumPy
I am aware of suggested best practices for random number generation in NumPy, which basically boil down to:
Use the new API, via np.random.default_rng and related functions; and
Set a seed at the ...
8
votes
4
answers
332
views
Generate 4 random numbers between -1.0 and 1.0 such their sum is 1 using python
I am trying generate 4 random numbers between -1.0 and 1.0 such that their sum is 1 using python.
I initially looked at the dirichlet function in numpy but that only works for positive numbers.
One ...
-1
votes
1
answer
64
views
Comparing numpy versus scipy when sampling random values from a poisson distribution [closed]
I am generating random samples from both numpy and scipy for a Poisson distribution, but it appears that scipy never produces values of x=0. Scipy seems to be off by x=1, i.e., it is shifted to the ...
1
vote
2
answers
91
views
Subtracting 1 from a numpy array gives two different answers
Why are outputs in the two cases different. I am new to this library
Case 1
import numpy as np
np.random.seed(2)
array = np.random.random((3,1))
print('Printing array : \n', array)
print('printing ...
2
votes
1
answer
109
views
How to sample Pandas DataFrame using a normal distribution by using random_state and numpy Generators
I am trying to write Pandas code that would allow me to sample DataFrame using a normal distribution. The most convinient way is to use random_state parameter of the sample method to draw random ...
4
votes
5
answers
162
views
Efficiently draw random samples without replacement from an array in python
I need to draw random samples without replacement from a 1D NumPy array. However, performance is critical since this operation will be repeated many times.
Here’s the code I’m currently using:
import ...
0
votes
2
answers
63
views
Randomly flip exactly n elements in multiple 2d matrices
I need to flip exactly randomly n (n>2) chosen elements (uniformly distributed) in total in m 2d numpy matrices with varying sizes (see initialization of my code), which I have stored in a ...
1
vote
2
answers
94
views
How to easily perform this random matrix multiplication with numpy?
I want to produce 2 random 3x4 matrices where the entries are normally distributed, A and B. After that, I have a 2x2 matrix C = [[a,b][c,d]], and I would like to use it to produce 2 new 3x4 matrices ...
3
votes
1
answer
92
views
How does np.random.integers() move the current rng seed?
I am trying to preserve the sequence of a random number generator as carefully as possible. However the following code shows that there seem some problem with the progression of the current random ...
0
votes
7
answers
253
views
How to Generate a Cumulative Sum of 300,000,000 Random 1s and -1s
I am trying to find an efficient way to generate a cumulative sum of 300,000,000 random 1s and -1s in Python. I have been able to use the solution below with n up to about 30,000,000. But if I try ...
1
vote
1
answer
46
views
Iteration of a graph approximation
The code below runs a model based on a graph generated by the solution to a system of differential equations and shows one with random 5% error added to the points. How would I iterate this process (...
1
vote
1
answer
99
views
Generate n random 2D points within a valid region
I want to generate a fixed number of random-uniformly distributed xy points within a valid mask.
The generated points should be continuous, i.e. can be "between pixels".
I'm looking for an ...
0
votes
0
answers
119
views
Numba and Numpy Generator Methods & Thread Safety Documentation Clarification
The Numba documention for the Numpy Random module states:
The current Numba support for Generator is not thread-safe, hence we do not recommend using Generator methods in methods with parallel ...
1
vote
1
answer
103
views
In Python with numpy, how to get uniformly distributed random floats between 0 and a natural x, including both?
In Python with numpy, for a given natural number x, we'd like to get an array (say, 20×2 or whichever shape you wish) of uniformly distributed floats in the interval [0,x]. Notice that the interval is ...