根据区间获取权重的所有排列
如果我有给定数量的“系统”
var nbSystems = 2;
和多个“步骤”,
var nbSteps = 3;
我如何生成以下所有排列:
{0.00, 0.00}
{0.33, 0.00}
{0.67, 0.00}
{1.00, 0.00}
{0.00, 0.33}
{0.33, 0.33}
{0.67, 0.33}
{1.00, 0.33}
{0.00, 0.66}
{0.33, 0.66}
{0.67, 0.66}
{1.00, 0.66}
{0.00, 1.00}
{0.33, 1.00}
{0.67, 1.00}
{1.00, 1.00}
我需要每个系统的权重在 0 到 1 之间,并且我想找到所有排列。
您会看到用于系统权重的间隔是根据 nbSteps 计算得出的(间隔 = 1 / nbSteps)。
我想要一个函数,它接受输入 nbSystems 和 nbSteps (或更好?),并且将输出某种具有所有排列的多维数组......
If I have a given number of 'systems'
var nbSystems = 2;
and a number of 'steps'
var nbSteps = 3;
How can I generate all the following permutations :
{0.00, 0.00}
{0.33, 0.00}
{0.67, 0.00}
{1.00, 0.00}
{0.00, 0.33}
{0.33, 0.33}
{0.67, 0.33}
{1.00, 0.33}
{0.00, 0.66}
{0.33, 0.66}
{0.67, 0.66}
{1.00, 0.66}
{0.00, 1.00}
{0.33, 1.00}
{0.67, 1.00}
{1.00, 1.00}
I need a weight between 0 to 1 for each system and I want to find all permutations.
You see that the interval to use for the systems weights is calculated from the nbSteps (interval = 1 / nbSteps).
I would like to have a function that takes inputs nbSystems and nbSteps (or better?) and that will output some sort of multidimensional array with all the permutations...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
痴者2024-12-03 17:43:17
尝试
double nbSteps = 3.0;
IEnumerable<double> SystemA = Enumerable.Range (0, (int)nbSteps).Select (x => x / nbSteps);
IEnumerable<double> SystemB = Enumerable.Range (0, (int)nbSteps).Select (x => x / nbSteps);
var Result = from a in SystemA from b in SystemB select new { a, b };
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
这应该可以做到:
如果您关心组合的顺序,请根据需要进行调整。
编辑:哎呀,修正了一个拼写错误 - 我在类型签名中调换了“max”和“min”。
This should do it:
Adjust as necessary if you care about the order of the combinations.
EDIT: Oops, fixed a typo - I transposed "max" and "min" in my type signature.