The `random` package within `numpy` deals with generating numbers or symbols according to well-known probability functions.
Questions tagged [numpy-random]
74 questions
0
votes
1 answer
Can't assign the "sum of np.random.normal" in a element of array
I am trying to produce random number by random.normal and take the summary of them. Then, I tried to assgin the value to each element in the array sum.
I made a zero array (float type) by np.zeros and then assign the value in following way.
I…

XYJ
- 11
- 5
0
votes
0 answers
Randomly sampling similar distributions
I want to find a robust way to sample distributions that are similar to an existing distribution. This new distribution should be at least r/2 away from the original distribution, but at most r away. This should ideally work for varying values of r…

MATH101
- 23
- 3
0
votes
1 answer
np.random.choice conflict with multiprocessing? multiprocessing inside for loop?
I want to use np.random.choice inside a multiprocessing pool, but I get the IndexError: list index out of range. I don't get any error when I use the choice function inside a for loop (in series then, not parallel). Any ideas on how to overcome…

Darrell Kartrip
- 97
- 1
- 5
0
votes
2 answers
How to inspect BitGenerator state in a numpy.random.Generator object?
If I have a numpy.random.Generator, what's the best way to inspect the BitGenerator used internally? And does the BitGenerator have any state that impacts what numbers are generated?

william_grisaitis
- 5,170
- 3
- 33
- 40
0
votes
1 answer
numpy.random.choice with percentages not working in practice
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:
…

Layla
- 347
- 1
- 6
- 13
0
votes
0 answers
KeyError pops up each time a function is called
Hi I am trying to implement the Siamese Neural Network for one-shot image recognition with the Omniglot dataset. The initial step for the implementation requires to generate pair samples with same/distinct classes, for that I use the make_pair…

ChengLong Deng
- 13
- 4
0
votes
1 answer
How a random number is generated in Numpy if I don't use Generator or RandomState?
I have read the Doc of Numpy,but I still don't know how a random number is generated if I don't use Generator or RandomState.
As far as I know,we can get a random number from 1 to 10 by
#use…

Amess
- 3
- 2
0
votes
1 answer
How can I create a random walk (with certain probability) for stock price movement in python?
I want to simulate stock price movements in Python, for 3 years, with a total of 300 steps, with 5 paths.
The share price can go up or down with probability of increase = q and probability of falling = 1-q.
If it increases, the price in period t =…
0
votes
2 answers
Why does numpy.random.Generator.choice gives different results even if given fixed seed?
The code is simple:
import numpy
rng = numpy.random.default_rng(0)
control = rng.choice([0,1],p=[0.5,0.5])
for i in range(100):
print(control == rng.choice([0,1],p=[0.5,0.5]))
# Not only True gets printed
Probably I am missing something, but…

Andrei
- 961
- 1
- 9
- 29
0
votes
1 answer
Random number generator with exclusions
I have 9x9 numpy array filled with numbers [1;9]. I need to pick random position and assign this cell as 0 until I get certain difficulty value. By the way, my table should satisfy certain criterias and functions were checked on multiple tests.…

Илия Оборотов
- 13
- 3
0
votes
1 answer
Incoherence in complementary indices extracted from a np.array
The problem is very simple, I have a vector of indices from which I want to extract one set randomly chosen and its complement. So I write the following code:
import numpy as np
vec = np.arange(0,25000)
idx = np.random.choice(vec,5000)
idx_r =…

Yule Vaz
- 3
- 1
0
votes
1 answer
How to use numpy's random number generator in a ufunc?
Basically I have a ufunc that requires some randomness. In order to keep the ufuncs as reproducible as possible I would like to use numpy's random number generator for that; basically because setting the seed will be more intuitive this way.
However…

LittleByBlue
- 436
- 9
- 18
0
votes
1 answer
What is the maximum number of pseudo-random numbers that can be generated with numpy.random before the sequence begins to repeat?
I need to generate many hundreds of millions of random numbers for a clustering analysis. I am using numpy.random and was wondering if anyone knows the maximum number of pseudo-randoms that can be generated with numpy.random before the sequence…

aim
- 657
- 2
- 12
- 26
0
votes
1 answer
Python drop random numbers of a beta distribution
I have a question about beta distributions and random variables. My data includes performance data from 2012 to 2016 on an hourly basis. I recalculated the data monthly, so I have only one value for every month. After that, I created a new df with…

Pyrmon55
- 183
- 1
- 3
- 14
0
votes
1 answer
If-Else statement works weird in Python
import numpy as np
import sklearn
import sklearn.datasets
from sklearn import svm
x = np.array([1,3,67,8])
print(x)
print(type(x))
if type(x) != int:
y = x.astype(int)
print(y)
print(type(y))
else:
print ("X is already an…
user5903986