python

python常见库

python

os

1
2
3
chdir(path)
Change the current working directory to the specified path.
path may always be specified as a string.

random

1
2
3
sample(population, k) method of random.Random instance
Chooses k unique random elements from a population sequence or set.
从population随机选取k个不同的元素,以list返回

iter

1
2
3
4
5
6
7
iter(...)
iter(iterable) -> iterator
iter(callable, sentinel) -> iterator

Get an iterator from an object. In the first form, the argument must
supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the sentinel.

next

1
2
3
4
5
next(...)
next(iterator[, default])

Return the next item from the iterator. If default is given and the iterator
is exhausted, it is returned instead of raising StopIteration.

zip

1
2
In: list(zip(*[[1,2,3],['1',2,3],[1,2,3],[1,2,3]]))
Out: [(1, '1', 1, 1), (2, 2, 2, 2), (3, 3, 3, 3)]

numpy

random

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
choice(...) method of mtrand.RandomState instance
choice(a, size=None, replace=True, p=None)

Generates a random sample from a given 1-D array

Parameters
-----------
a : 1-D array-like or int
If an ndarray, a random sample is generated from its elements.
If an int, the random sample is generated as if a were np.arange(a)
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
``m * n * k`` samples are drawn. Default is None, in which case a
single value is returned.
replace : boolean, optional
Whether the sample is with or without replacement
p : 1-D array-like, optional
The probabilities associated with each entry in a.
If not given the sample assumes a uniform distribution over all
entries in a.

Returns
--------
samples : single item or ndarray
The generated random samples

Examples
---------
Generate a uniform random sample from np.arange(5) of size 3 without
replacement:

np.random.choice(5, 3, replace=False)
array([3,1,0])
#This is equivalent to np.random.permutation(np.arange(5))[:3]

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!