understanding min and max values of randn while using NumPy

Viewed 1111

I am fairly new to Python and learning some basic python for data science, and I am trying to ascertain the min and max values for an array when you run randn.

to clarify the question, how potentially low and high could the below numbers get?

does it have anything to do with the row/column values entered?

I thought they were for values between -1 and 1 but this is not the case when I test.

import numpy as np
np.random.randn(3,3)
array([[ 1.61311526, -1.20028357, -0.41723647],
       [-0.31983635, -3.05411198, -0.43453723],
       [ 0.09385744, -0.28239577, -1.17262933]])
5 Answers

Standard Normal Distribution

As mentioned by others, graphically, the probability distribution looks like this.

Probability of getting a value from -0.5 to 0.5: 19.1% + 19.1% = 38.2% Probability of getting a value larger than 3 = 0.1%

np.random.randn return a sample (or samples) from the “standard normal” distribution (see documentation here).

The standard normal distribution is not bounded. However, the probability for example to get a sample smaller than -3 is 0.0013.

The function numpy.random.randn returns values from the standard normal distribution, which can be anything between negative and positive infinity, so there's no max or min. These values are distributed along the "bell curve" centered at 0, and are exponentially less likely to occur the farther you get from 0.

The row/column parameters don't affect determine any (non-existent) max/min, they just determine the shape of the output array (see the documentation)

So in your example, passing (3,3) into np.random.randn(3,3) returns a 3x3 array of values from the standard normal distribution.

Basically, there's no max or min value, but since higher numbers are less likely to come up or in other words have lower probabilities, you're usually only looking at -3.5 to 3.5. But the larger the size of random data you are trying to generate, the higher the chances of generating a larger value.

The numpy.random.randn function is based on a standard normal distribution, meaning that there is not a maximum value or a minimum value. However, more positive and negative values are less likely to be produced than ones closer to zero.

Related