Questions tagged [numpy-random]

The `random` package within `numpy` deals with generating numbers or symbols according to well-known probability functions.

74 questions
1
vote
2 answers

Function that generates random numbers calls other function that generates random numbers with a seed, and seed seems to be used again

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 that it will always be the same for a fixed seed.…
Tucci
  • 13
  • 3
1
vote
1 answer

CuPy and Dirichlet gives me TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'

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 do the same thing with cupy import cupy as cp A…
1
vote
2 answers

error while using Numpy Random function (np.random.random_integers)

enter image description here Error while using numpy random function, it shows int object not callable please suggest alternative
1
vote
1 answer

How to efficiently perform billions of Bernoulli extractions using numpy?

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 infected and a susceptible node. I am using…
1
vote
2 answers

How to use a function argument as npy method, if possible

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 require 1 argument that is okay. Just really stuck…
Candy
  • 21
  • 6
1
vote
0 answers

How can I fix the error: "ValueError: 'a' and 'p' must have the same size" for mtrand.RandomState.choice module?

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 new population by doing some crossover. The problem…
Colin Gregory
  • 55
  • 1
  • 1
  • 5
1
vote
1 answer

Numpy RNG non-deterministic even when seeded

I'm using numpy.random for a Monte Carlo simulation where very small acceptance/rejection probabilities are possible. Although I'm seeding the RNG, I'm unable to reproduce the same sequence of random numbers. In numpy 1.15.1's documentation it…
Botond
  • 2,640
  • 6
  • 28
  • 44
1
vote
1 answer

Filling a zeros array at limited number of random places except diagonal ones

I have a 2D numpy array which has only 0s in (N,N) size. I randomly want to insert twelve 1s to this array while keeping the diagonal locations' value equal to 0. What I have tried until now is : import numpy as np def func(N=20): x=…
bapors
  • 887
  • 9
  • 26
1
vote
1 answer

How to properly sample from a numpy.random.multivariate_normal (positive-semidefinite covariance matrix issue)

I'm hoping to generate new "fake" data from the data I already have with numpy.random.multivariate_normal. With n samples and d features in an n x d pandas DataFrame: means = data.mean(axis=0) covariances = data.cov() variances =…
Alex Lenail
  • 12,992
  • 10
  • 47
  • 79
1
vote
1 answer

Explanation required in seaborn tutorial

I am learning seaborn from http://seaborn.pydata.org/tutorial/aesthetics.html In the import section,please explain this line np.random.seed(sum(map(ord, "aesthetics"))) What this line does and please explain each element in this line. In plotting…
Jayashree
  • 811
  • 3
  • 13
  • 28
1
vote
4 answers

Numpy Choose Elements from 2 arrays

I need to choose n items from 2 arrays such that the indices are the same. So, for instance, I need to choose two items from x randomly, and pick elements from y such that y's chosen indices are the same as x's: x =…
Chris
  • 28,822
  • 27
  • 83
  • 158
1
vote
0 answers

Generating a Series of Alternating Exponential Processes Elegantly

Suppose I start with a time series: time = pd.date_range('1/1/2011', periods=600, freq='5M') I'd like now to generate a corresponding series, say 'on', so that the entries of 'on' will correspond to an exponential process that is True with mean 10,…
Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
0
votes
1 answer

How to restore matlab random generator state into numpy?

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('rand_state.mat', 's'); %... random functions that…
0
votes
1 answer

Create Numpy array from list of arbitrary sized bites

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)] numpy_array = # make array from byte_list # do something…
aabceh
  • 95
  • 7
0
votes
0 answers

How numpy Gaussian Distribution works?

I am new to numpy. There is a part which in not so clear to me in numpy gaussian distribution. from numpy import random x = random.normal(size=(2, 3)) print(x) This generate x as: [[ 1.15917179 -1.29036526 0.88074813] [-1.07674284 2.35437249…