标签:methods call oms 应用 操作 nes oat perm pos
http://blog.csdn.net/pipisorry/article/details/39508417
RandomState exposes a number of methods for generating random numbersdrawn from a variety of probability distributions.
使用示例
prng = np.random.RandomState(123456789) # 定义局部种子
prng.rand(2, 4)
prng.chisquare(1, size=(2, 2)) # 卡方分布
prng.standard_t(1, size=(2, 3)) # t 分布
prng.poisson(5, size=10) # 泊松分布
[概率与统计分析]
[class numpy.random.RandomState]
random.seed(123456789) # 种子不同,产生的随机数序列也不同,随机数种子都是全局种子
要每次产生随机数相同就要设置种子,相同种子数的Random对象,相同次数生成的随机数字是完全相同的;
random.seed(1)
这样random.randint(0,6, (4,5))每次都产生一样的4*5的随机矩阵
This method is called when RandomState is initialized. It can be called again to re-seed the generator.
关于种子的介绍可参见[Java - 常用函数Random函数]
linspace(start, end, num): 如linspace(0,1,11)结果为[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1];
arange(n): 产生一个从0到n-1的向量,如arange(4)结果为[0,1,2,3]
rand(d0, d1, ..., dn) | Random values in a given shape. |
randn(d0, d1, ..., dn) | Return a sample (or samples) from the “standard normal” distribution. |
randint(low[, high, size, dtype]) | Return random integers from low (inclusive) to high (exclusive). |
random_integers(low[, high, size]) | Random integers of type np.int between low and high, inclusive. |
random_sample([size]) | Return random floats in the half-open interval [0.0, 1.0). |
random([size]) | Return random floats in the half-open interval [0.0, 1.0).产生随机矩阵,如random.random([2,3])产生一个2x3维的随机数 |
ranf([size]) | Return random floats in the half-open interval [0.0, 1.0). |
sample([size]) | Return random floats in the half-open interval [0.0, 1.0). |
choice(a[, size, replace, p]) | Generates a random sample from a given 1-D array |
bytes(length) | Return random bytes. |
[Simple random data?]
from numpy import random
x = random.rand(2, 3) print(x) [[ 0.1169922 0.08614147 0.17997144] [ 0.5694889 0.43067372 0.62135592]]
x, y = random.rand(2, 3) print(x) print(y) [ 0.60527337 0.78765269 0.71884661] [ 0.67420571 0.946359 0.7632273 ][numpy - 基本数据类型、多维数组ndarray及函数操作]
raw_user_item_mat = random.randint(0, 10, size=(3,4)) #指定生成随机数范围和生成的多维数组大小 print(raw_user_item_mat) [[3 6 2 8] [3 1 2 4] [9 4 5 0]][Random sampling (numpy.random)]
normal_values = np.random.normal(size=N) #lz一般使用stats.norm.rvs(loc=0, scale=0.1, size=10)来生成高斯分布随机数[Scipy教程 - 统计函数库scipy.stats]
#绘制分布直方图和理论上的概率密度函数(均值为0、方差为1的正态分布)曲线。plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) * np.exp( - (bins -mu)**2 / (2 * sigma**2) ),lw=2) #lz提示,也可以使用scipy.stat.norm.pdf来生成非随机的高斯分布图[Scipy教程 - 统计函数库scipy.stats]
random_index = np.ones_like(class_labels, dtype=bool) random_index[np.random.choice(range(len(data_arr)), n1, replace=False)] = False D1 = data_arr[random_index] D1_left = data_arr[~random_index]
from:http://blog.csdn.net/pipisorry/article/details/39508417
标签:methods call oms 应用 操作 nes oat perm pos
原文地址:https://www.cnblogs.com/fujian-code/p/9029559.html