- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
例如:
我想把33.38分成5份,每份都等于或大于1.2:
2.71,3.3,18.7,1.56,7.11
伪代码中的函数:
public static void printRandomPartition(float value,int numberOfParts,float pMin){
}
public static void main(String[] args){
//it will print 2.71,3.3,18.7,1.56,7.11
printRandomPartition(33.38,5,1.2);
}
另一种情况:
将18.77分成3份,每份等于或大于3.2:
4.8,9.55,4.42
当然输入和输出可能是丑陋的格式 float ,例如 3.82000000000003,这只是示例而已。
我查了一些帖子,好像大部分都是关于整数的,而且整数中使用的方法经常使用array int myArray[n](n是要除的整数),这对处理 float 没有用。谁能帮忙?
最佳答案
伪代码
function Divide(Sum, NParts, MinValue)
//subtract minimal values to deal with corrected sum
ASum = Sum - MinValue * NParts
//generate uniform randoms (in any reasonable range), take their sum
BSum = 0
for i = 0.. NParts - 1
Part[i] = Random
BSum = BSum + Part[i]
//scale randoms to get right corrected sum, then add minimal value to get initial sum
for i = 0.. NParts - 1
Part[i] = Part[i] * ASum / BSum + MinValue
关于algorithm - 如何生成 float 的随机分区并且每个部分都有最小值pMin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30660057/
pmin在以下示例中不会返回适当的输出。 eps <- 1e-16 x <- structure(list(X = c(0.219801587301587, 0.340792857142857, 0.
我有这样一张表: structure(list(Suggested.Symbol = c("CCT4", "DHRS2", "PMS2", "FARSB", "RPL31", "ASNS"), gwa
我有这样一张表: structure(list(Suggested.Symbol = c("CCT4", "DHRS2", "PMS2", "FARSB", "RPL31", "ASNS"), gwa
这是一个相当简单的问题。出于某种原因,当使用数据帧进行管道传输时,pmin() 函数不起作用。见下文: library(dplyr) data(mtcars) pmin(mtcars$am, mtca
下面的代码摘录在 Array1 是填充的 3 维数组的情况下工作正常: LotsMaxs <- pmax.int(Array1[,1,],Array1[,2,],Array1[,3,],Array1[
有没有办法在 R 中使用 pmax 和 pmin 函数以及使用 tidyverse (dplyr) 格式的字符串变量名称向量? 例如,我想运行以下命令: data(mtcars) mtcars %>%
在尝试回答时 this question ,我遇到了mutate之间的区别和 transform在我期望的等效操作中。 # data x % mutate(a=pmin(a,b), b=pmax(a,
我想提取存储在列表中的多个矩阵的每个元素的最小值。我正在使用 pmin: do.call(pmin, mylist) 问题是这些矩阵的某些元素是 NA,并且 pmin 产生一个 NA,我希望它在排除
我正在尝试使用 pmin 函数和 data.table(类似于帖子 row-by-row operations and updates in data.table )计算跨行的最小值,但使用类似 wi
似乎 R 可能缺少一个明显的简单函数:psum .它是否以不同的名称存在,还是在某个包中? x = c(1,3,NA,5) y = c(2,NA,4,1) min(x,y,na.rm=TRUE)
我是一名优秀的程序员,十分优秀!