knsaicharan
knsaicharan

Reputation: 115

What is the difference between test1 = np.random.randint((11, 20, 50)) and test1 = np.random.randint(11, 20, 50)

While the 1st one gives me a solution

test1 = np.random.randint((11, 20, 50))
>>> random array with order (1,3) 

ex- array([ 1, 3, 43])

While the second one gives

test1 = np.random.randint(11, 20, 50)
>>> 50 random values b/w 11 to 20 in an array

ex- array([17, 16, 14, 16, 18, 19, 19, 13, 13, 13, 14, 12, 16, 12, 16, 17, 19, 19, 12, 14, 17, 11, 19, 14, 16, 13, 17, 12, 12, 19, 14, 18, 15, 17, 11, 12, 15, 16, 13, 16, 14, 19, 12, 18, 12, 15, 13, 14, 16, 12])

So my question is why does it behave differently with only () parentheses

Upvotes: 0

Views: 54

Answers (1)

hpaulj
hpaulj

Reputation: 231395

Your two cases are the same as:

In [211]: np.random.randint(low=0,high=(11, 20, 50),size=3)                                    
Out[211]: array([ 2, 17,  7])
In [212]: np.random.randint(low=11, high=20, size=50).shape                                    
Out[212]: (50,)

One returns one value for each of the ranges defined by the low and high tuples, the other returns multiple values evaluated on one common range.

The second is the most common usage. The first is a convenience that someone though would be useful for some people. It might not be widely used or well thought out. I wouldn't put a lot of effort into understanding it, unless I really had a need for something like that.

Upvotes: 1

Related Questions