我有一个数组(分布),我想在a
和b
的某个范围内进行此分布,这是通过使用函数qunif
在R中完成的,我想在Python中执行此操作会产生不同的结果:
a <- c(0.012701112, 0.131852757, 0.230918602, 0.382584686, 0.422162992,
0.553339539, 0.64807742, 0.735555988, 0.813598841, 0.975585224)
b <- qunif(a, -4, 4)
b
# -3.8983911 -2.9451779 -2.1526512 -0.9393225 -0.6226961
# 0.4267163 1.1846194 1.8844479 2.5087907 3.8046818
import scipy.stats as stats
a = [0.012701112, 0.131852757, 0.230918602, 0.382584686, 0.422162992,
0.553339539, 0.64807742, 0.735555988, 0.813598841, 0.975585224]
b = stats.uniform.ppf(a, -4, 4)
b
# [-3.94919555 -3.47258897 -3.07632559 -2.46966126 -2.31134803
# -1.78664184 -1.40769032 -1.05777605 -0.74560464 -0.0976591 ]
我看到here这两个功能是等效的。
答案 0 :(得分:5)
The SciPy stats.uniform
由loc
和scale
参数化,而R函数由min
和max
参数化。等效的SciPy为
b = stats.uniform.ppf(a, loc=-4, scale=8)
b
# array([-3.8983911 , -2.94517794, -2.15265118, -0.93932251, -0.62269606,
# 0.42671631, 1.18461936, 1.8844479 , 2.50879073, 3.80468179])