+ 3

what is" numpy.random.random_intrgers" do? i read about it in scipy.org but couldn't understand

4th Oct 2018, 2:55 PM
sama baluom
sama baluom - avatar
9 ответов
+ 2
numpy.random.random_integers(1, 10) would return an integer between 1 and 10 (both inclusive) chosen randomly. So we don't exactly know what the output will be, but it must something in the set {1,2,...,10}. All that stuff about discrete uniform distribution means that the probability of it picking each integer in the range is the same. So, since there are 10 numbers in 1-10, on an average, each number will be picked one-tenth of the time. By the way, the documentation also says that we are encouraged to use numpy.random.randint instead. It is similar, but output of randint(1,10) is an integer between 1 and 9. 10 is not included this time, just like range() in Python. Is there anything specific that you don't understand? I'll be happy to explain in more detail.
4th Oct 2018, 4:45 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
My pleasure! I actually learnt about this function while trying to answer your question. So, thank YOU! 😊 Please feel free to ask more questions! And good luck on your exam, I'm sure you'll do great!
4th Oct 2018, 4:57 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
Actually, my previous answer is not complete. There is an optional argument which may be really useful in creating random arrays. Consider numpy.random.random_integers(1, 10, (2,3)) This would create an array of size 2x3 (so 2 rows, 3 columns), and the entries of the array will be those random numbers between 1 and 10 (inclusive). Similarly for randint, but just like before, the number 10 will not be included this time.
4th Oct 2018, 5:10 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
thanks^^ so the answer (by example ) array([[3,6,1], [4,2,2], [9,0,1]])
4th Oct 2018, 5:14 PM
sama baluom
sama baluom - avatar
+ 2
Yes, that would be the answer if I had (3,3) as the size argument, since you have 3 rows and 3 columns. For (2,3), it'd look like [[2,9,7], [4,1,6]]
4th Oct 2018, 5:18 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
thank youuu! its very clear now😆
4th Oct 2018, 4:48 PM
sama baluom
sama baluom - avatar
+ 1
we just learnt numpy two days ago and have python exam next week! thank for help ;)
4th Oct 2018, 4:49 PM
sama baluom
sama baluom - avatar
+ 1
its hard
15th Oct 2018, 8:25 AM
Jess Mole
Jess Mole - avatar
+ 1
Jess Mole not at all;)
15th Oct 2018, 9:00 AM
sama baluom
sama baluom - avatar