Questions tagged [numpy-random]

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

74 questions
0
votes
1 answer

Only size 1 arrays can be converted to python scalars

I created a 3 dimensional object using numpy.random module such as import numpy as np b = np.random.randn(4,4,3) Why can't we cast type float to b? TypeError actual code
Stark Wayne
  • 3
  • 1
  • 1
  • 4
0
votes
1 answer

Evaluate the probability density of Gaussian distribution on a square grid

I need to generate an image mask of dimensions m × n corresponding to a two-dimensional Gaussian with center at µ = (i, j) and σ^2 = 25, using NumPy. After searching on the net, I found this documentation which looks promising. However, there are a…
Rodrigo Laguna
  • 1,796
  • 1
  • 26
  • 46
0
votes
0 answers

How to edit code to get a prediction value in expected range?

I have tried a simple neural network tutorial found on the internet. But I expect change it a bit. Original code predicts values between 0-1. But I want to change it as 0-10. How can I do it? As I understand, these are he lines should be considered…
Joe
  • 45
  • 1
  • 9
0
votes
1 answer

Discrepancy of the state of `numpy.random` disappears

There are two python runs of the same project with different settings, but with the same random seeds. The project contains a function that returns a couple of random numbers using numpy.random.uniform. Regardless of other uses of numpy.random in…
noname
  • 343
  • 4
  • 14
0
votes
0 answers

Bulletproof seeding of random generators to ensure computational reproducibility in Python

My intention is to create a guideline on how to do reproducible computations in Python (if possible, regardless the environment, the operating system, etc.). However the issue of generating random numbers keeps coming back to my mind. I am…
Marek
  • 815
  • 8
  • 19
0
votes
1 answer

What is the purpose of using np.random.random(4) for plotting pie charts using matplotlib?

I am relatively new to matplotlib. ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True, startangle=90, radius=0.25, center=(0, 0), frame=True) ax.pie(np.random.random(4), explode=explode,…
Amogh Mishra
  • 1,088
  • 1
  • 16
  • 25
-1
votes
1 answer

Why does np.random.choice take so much longer than np.random.randint?

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.choice(100) and import numpy as np for i in…
Trahtorco
  • 9
  • 3
-1
votes
1 answer

Generate bootstrap sample from ndarray

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 following works for 1-dimensional arrays. import numpy as…
mj_whales
  • 124
  • 2
  • 11
-1
votes
1 answer

Handwritten Digit Recognition on MNIST dataset using sklearn

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 correct way to do it. from sklearn.datasets…
-1
votes
1 answer

Generating a probability distribution P(y) from another probability distribution P(x) such that highest probability in P(x) is least likely in P(y)

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 from this dictionary and increment the counters as I select the particular…
-1
votes
2 answers

swap locations of an element in numpy array

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 [array([1, 2, 3]), array([2, 3, 1]), array([1, 3,…
-1
votes
1 answer

Numpy shuffle array

I'm using Numpy to shuffle an array with about 1 million entries. The resulting array doesn't seem to be in random order at all, I can see sequences. Eg if the original is: ar = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] then I see sequences like this in the…
tdma
  • 182
  • 1
  • 12
-2
votes
2 answers

Randomly change x amount of values to y in a z size array

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 set. Is there a way to do this in numpy?
-7
votes
2 answers

Why does this code use only x instead of both x and y in for loop?

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 results in euclidean_distances_vector_l list X =…
Joshua
  • 11
  • 4
1 2 3 4
5