What does sample mean in python?

silencement
Release: 2020-09-19 13:57:39
Original
40000 people have browsed it

What does sample mean in python?

sample is a function in the random module

The expression is:

random.sample(sequence, k)
Copy after login

its function is Randomly obtain fragments of the specified length from the specified sequence and arrange them randomly, and return the result in the form of a list . Note: The sample function will not modify the original sequence.

For example:

What does sample mean in python?

Other usage methods in the random module

1, random.random Randomly generate [0.1) floating point number

2. random.uniform

The prototype is: random.uniform(a, b), which is used to generate a random number of character points within a specified range. One of the two parameters is the upper limit. , one is the lower limit. If a > b, the generated random number n: a

3. andom.randint
The prototype is: random.randint(a, b), used to generate an integer within a specified range. The parameter a is the lower limit, the parameter b is the upper limit, and the generated random number n: a

4, random.choice

The prototype is: random.choice(sequence). The parameter sequence represents an ordered type. Let me explain here: sequence is not a specific type in python, but generally refers to a series of types. List, tuple, and string all belong to sequence (dictionaries and collections are unordered)

5. ****random.shuffle
The prototype is: random.shuffle(x[, random]) , used to scramble the elements in a list.

Related learning recommendations: python tutorial

The above is the detailed content of What does sample mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!