
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Generate Random Numbers Using Python Numpy
The random module in Numpy package contains many functions for generation of random numbers
numpy.random.rand() − Create an array of the given shape and populate it with random samples
>>> import numpy as np >>> np.random.rand(3,2) array([[0.10339983, 0.54395499], [0.31719352, 0.51220189], [0.98935914, 0.8240609 ]])
numpy.random.randn() − Return a sample (or samples) from the “standard normal” distribution.
>>> np.random.randn() -0.6808986872330651
numpy.random.randint() − Return random integers from low (inclusive) to high (exclusive).
>>> np.random.randint(5, size=(2, 4)) array([[2, 4, 0, 4], [3, 4, 1, 2]])
numpy.random.random() − Return random floats in the half-open interval [0.0, 1.0).
>>> np.random.random_sample() 0.054638060174776126
Advertisements