Generate a random array using numpy

Source: Internet
Author: User

Python is convenient to use the random library to generate random numbers. However, if you want to generate random arrays, numpy is better and bigger.

Generate a random array with a length of 10 and evenly distributed between [0, 1:

 
Rarray = numpy. Random. Random (size = 10)

Or

 
Rarray = numpy. Random. Random (10 ,))

Generate an average distribution between-0.1 and 0.1:

 
Rarray = 0.2 * numpy. Random. Random (size = 10)-0.1

Or

 
Rarray = numpy. Random. Uniform (-0.1, 0.1, size = 10)

Convert to normal List format

Rlist = List (rarray)

For more details about how to generate an evenly distributed random number, see numpy. Random. Random.

Generate a random number with a length of 10 and conform to the normal distribution.

 
Mu, Sigma = 0, 0.1 # mean and standard deviation rarray = numpy. Random. Normal (MU, Sigma, 10)

For more details about how to generate a random number with a normal distribution, see numpy. Random. Normal.

For details about other random numbers and more operations, see numpy. Random.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.