Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
83 views

I was looking through some codes and saw this line, numpy.random.normal(size=x.shape). Where, x = numpy.linspace(1, 2, 100). I don't understand what this does. I've only come across, np.random.normal(...
Govind's user avatar
  • 25
1 vote
3 answers
250 views

I need to make a function that takes in an array of integers and returns a list of random numbers with the same length as the array. However, there is the restriction that the output random number ...
rtg142857's user avatar
2 votes
1 answer
108 views

In case it matters at all, I'm using Python 3.11.5 64-bit on a Windows 11 Pro desktop computer with NumPy 1.26.4. In order to try to better understand what NumPy is doing behind the scenes when I ask ...
Mel's user avatar
  • 127
0 votes
1 answer
125 views

I have two arrays - array1 and array2. How confidently can I state that they are generated from uncorrelated distributions? Just checking the correlation values would not suffice; I would require p-...
Anirban Chakraborty's user avatar
0 votes
1 answer
66 views

I have a dataset below which shows if a customer is a return customer or not. The end goal is for all returned customers, I need to map about 25% of them to 'yes 1 purchase' and 75% of them to 'yes &...
user032020's user avatar
3 votes
2 answers
777 views

For my scientific experiments, I usually seed using: rng = np.random.Generator(np.random.PCG64(seed)) which for the current numpy version is equivalent to rng = np.random.Generator(np.random....
saper0's user avatar
  • 394
2 votes
1 answer
735 views

I have a question that is closely related to this one: Normed histogram y-axis larger than 1 The solution of the above thread was to scale the dimensions of the axis properly. However, that solution ...
Laulito's user avatar
  • 75
0 votes
1 answer
256 views

I've been reading that np.random.choice is faster than np.random.randint (here and here), however when comparing the speed difference between import numpy as np for i in range(100000): np.random....
Trahtorco's user avatar
0 votes
1 answer
94 views

I can save the state of matlab random generator with the following code seed = 10; rng(seed, 'twister'); %... random functions that don't need to be reproduced% s = rng; s.Type s.Seed s.State save('...
Divyansh Gupta's user avatar
0 votes
1 answer
66 views

How can I create a numpy array from a python list of bytes objects of an arbitrary (but known) size? Example: size = 10 byte_list = [np.random.default_rng().bytes(size) for i in range(100)] ...
aabceh's user avatar
  • 95
0 votes
1 answer
70 views

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 ...
XYJ's user avatar
  • 11
0 votes
0 answers
139 views

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. ...
MATH101's user avatar
  • 23
1 vote
3 answers
1k views

I'm playing around with some hardware entropy creation. I'm using electronic sensors to sample the environment, using A2D with between 12-16 bits of resolution. I'm hypothesizing that the lower-order ...
cbp2's user avatar
  • 245
-1 votes
1 answer
803 views

Is there a way to generate a bootstrap sample on an N-dimensional array? I am limited to using numpy==1.19.4 I have already tried using a for loop on the other dimensions to no avail, but the ...
mj_whales's user avatar
  • 122
3 votes
1 answer
1k views

I'm comparing the numbers generated with np.random.normal on two different systems (details see below) with the following code (I'm using the legacy np.random.seed because this is used by another ...
a_guest's user avatar
  • 36.7k
0 votes
1 answer
308 views

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, ...
Darrell Kartrip's user avatar
1 vote
1 answer
200 views

I am not sure if this question fits to numpy users or mathematicians. I don't understand how the numpy.random.multivariate_normal's example works. In the bottom of the documentation, it generates a ...
Shayan's user avatar
  • 170
1 vote
2 answers
310 views

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's user avatar
1 vote
2 answers
299 views

I am trying to generate a function which generate random numbers from a uniform distribution Number_Rand() and another one which generates a random number given a certain seed Number_Rand_Seed() - so ...
Tucci's user avatar
  • 13
2 votes
0 answers
962 views

In NumPy, I can use random package to create a 2D array, but cannot make sure it has full rank or a particular rank. How to got it? In the case of full rank, I can use linalg.matrix_rank to check, but ...
ydhhat's user avatar
  • 391
0 votes
1 answer
402 views

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):...
Layla's user avatar
  • 367
-1 votes
1 answer
456 views

I want to build a Handwritten Digit Recognition on MNIST dataset using sklearn and I wanted to shuffle my train set for both features(x) and label(y). But it shows a KeyError. Let me know what is the ...
varisha15's user avatar
0 votes
0 answers
156 views

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/...
ChengLong Deng's user avatar
-1 votes
1 answer
94 views

So the problem at hand is that I have some values in a dictionary with counters, let's say dict = {"cats":0, "dogs":0, "lions":0} I want to randomly select the keys ...
AZ123's user avatar
  • 194
1 vote
1 answer
272 views

I simply want to create a random matrix A whose vectors are drawn from the Dirichlet distribution. The function works fine with numpy: import numpy as np A = np.random.dirichlet(np.ones(n), n) When I ...
DimitrisMel's user avatar
0 votes
1 answer
77 views

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's user avatar
  • 3
3 votes
2 answers
4k views

The formula below is a special case of the Wasserstein distance/optimal transport when the source and target distributions, x and y (also called marginal distributions) are 1D, that is, are vectors. ...
develarist's user avatar
  • 1,395
2 votes
3 answers
553 views

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 /...
gojomo's user avatar
  • 54.5k
0 votes
1 answer
962 views

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 =...
bagus subscription's user avatar
2 votes
1 answer
552 views

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"...
Dazz W's user avatar
  • 123
1 vote
2 answers
279 views

enter image description here Error while using numpy random function, it shows int object not callable please suggest alternative
Ninad Nakhawa's user avatar
2 votes
2 answers
2k views

Simple test code: pop = numpy.arange(20) rng = numpy.random.default_rng(1) rng.choice(pop,p=numpy.repeat(1/len(pop),len(pop))) # yields 10 rng = numpy.random.default_rng(1) rng.choice(pop) # yields 9 ...
Andrei's user avatar
  • 993
0 votes
2 answers
2k views

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 ...
Andrei's user avatar
  • 993
4 votes
1 answer
3k views

Numpy documentation on np.random.permutation suggests all new code use np.random.default_rng() from the Random Generator package. I see in the documentation that the Random Generator package has ...
David Parks's user avatar
  • 32.4k
0 votes
1 answer
178 views

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 ...
Илия Оборотов's user avatar
11 votes
1 answer
3k views

The fact that NumPy now recommends that new code uses the default_rng() instance instead of numpy.random for new code has got me thinking about how it should be used to yield good results, both ...
Marcus's user avatar
  • 448
0 votes
1 answer
80 views

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,...
Yule Vaz's user avatar
-1 votes
2 answers
321 views

I have created a numpy array a=np.array([1,2,3]) a >>> array([1, 2, 3]) I would like to change the positions of the elements. My expected output should only consists of these three patterns ...
kamalesh waran's user avatar
3 votes
2 answers
2k views

I have a 2d array, say, a = [ [1, 2, 3, 4], [5, 6,7, 8], [9, 10, 11, 12], ...[21, 22, 23, 24] ], and I would like to pick N elements from each row randomly, based on a probability distribution p which ...
strugglinggrad's user avatar
8 votes
1 answer
4k views

I have been using numpy's random functionality for a while, by calling methods such as np.random.choice() or np.random.randint() etc. I just now found about the ability to create a default_rng object, ...
johannesack's user avatar
-2 votes
2 answers
60 views

New to python and was wondering if the above could be done using python and numpy. I have an array of let's say size 10, I want to change 6 random values from their current value to something else I ...
Yoinkers McGee's user avatar
1 vote
1 answer
959 views

I am working at a thesis about epidemiology, and I have to simulate a SI epidemic in a temporal network. At each time step there's a probability ~ Bernoulli(beta) to perform an extraction between an ...
wetrust's user avatar
  • 87
1 vote
2 answers
177 views

I am trying to create a function that will take a numpy dstr name as an argument and plot a histogram of random data points from that distribution. if it only works on npy distributions that ...
Candy's user avatar
  • 21
2 votes
0 answers
586 views

I have written a function to add poisson noise to an image using numpy with np.random.poisson(..). The image is already in numpy array form, using grayscale (0-255). I am wandering if it makes more ...
pierresegonne's user avatar
2 votes
2 answers
4k views

I am trying to split a list into n sublists where the size of each sublist is random (with at least one entry; assume P>I). I used numpy.split function which works fine but does not satisfy my ...
tcokyasar's user avatar
  • 592
0 votes
1 answer
136 views

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 ...
LittleByBlue's user avatar
1 vote
0 answers
26 views

I am implementing an algorithm to solve the 8-queens problem: https://en.wikipedia.org/wiki/Eight_queens_puzzle I have run into a problem when trying to iterate through the population and create a ...
Colin Gregory's user avatar
-7 votes
2 answers
131 views

Why have they only used X in for loop and not both X and Y? And why we are using reshape with 1, -1? # implement a loop which computes Euclidean distances between each element in X and Y # store ...
Joshua's user avatar
  • 11
2 votes
2 answers
5k views

I am puzzled about the right way to use np.random.RandomState with sklearn.model_selection.RandomizedSearchCV when running on multiple cores. I use RandomState to generate pseudo-random numbers so ...
hsafer's user avatar
  • 77
0 votes
1 answer
149 views

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 ...
Alex Merson's user avatar