参考链接:https://www.chzzz.club/post/137.html
numpy.random
DESCRIPTION
========================
Random Number Generation
========================
==================== =========================================================
Utility functions
==============================================================================
random_sample Uniformly distributed floats over ``[0, 1)``.
random Alias for `random_sample`.
bytes Uniformly distributed random bytes.
random_integers Uniformly distributed integers in a given range.
permutation Randomly permute a sequence / generate a random sequence.
shuffle Randomly permute a sequence in place.
seed Seed the random number generator.
choice Random sample from 1-D array.
==================== =========================================================
==================== =========================================================
Compatibility functions
==============================================================================
rand Uniformly distributed values.
randn Normally distributed values.
ranf Uniformly distributed floating point numbers.
randint Uniformly distributed integers in a given range.
==================== =========================================================
解释:
-
numpy.random.rand(d0, d1, ..., dn):生成一个[0,1)之间的随机浮点数或N维浮点数组。
-
numpy.random.randn(d0, d1, ..., dn):生成一个浮点数或N维浮点数组,取数范围:正态分布的随机样本数。
-
numpy.random.randint(low, high=None, size=None, dtype='l'):生成一个整数或N维整数数组,取数范围:若high不为None时,取[low,high)之间随机整数,否则取值[0,low)之间随机整数。
-
numpy.random.random_integers(low, high=None, size=None):生成一个整数或一个N维整数数组,取值范围:若high不为None,则取[low,high]之间随机整数,否则取[1,low]之间随机整数。
-
numpy.random.random_sample(size=None):生成一个[0,1)之间随机浮点数或N维浮点数组。
-
numpy.random.choice(a, size=None, replace=True, p=None):从序列a中获取元素,若a为整数,元素取值为np.arange(a)中随机数;若a为数组,取值为a数组元素中随机元素。replace=False表示不能重复,replace=True可以重复。p为与a长度相同的数组,可以决定a中每个元素随机出现的概率。p.sum()=1
-
numpy.random.shuffle(x):对X进行重排序,如果X为多维数组,只沿第一条轴洗牌,输出为None,改变原来的X
-
numpy.random.permutation(x):与numpy.random.shuffle(x)函数功能相同。输出为X洗牌后的新数组,原来的X不变。