c++ - 如何设置 "discrete_distribution"c++的 vector

标签 c++ vector random

我正在尝试模拟类似马尔可夫链的东西 并使用 discrete_distribution 来模拟状态 s_i 到 s_j 的变化。 但当然,这是一个矩阵,而不是 vector 。 所以我试试。

std::vector <uint16_t> v {{...},
                          {...},
                           ...
                          {...},};

std::vector <std::discrete_distribution <uint16_t> > distr(n, std::distribution <uint16_t> (v.begin(), v.end()) );

但这行不通。

注意:如果我只尝试 1 个 vector ,这是 uint16_t 作品的 vector

// CHANGE v by v[0]
std::vector<std::discrete_distribution <uint64_t>> distr(1, std::discrete_distribution <uint64_t> (vecs[0].begin(), vecs[0].end()));

基于此answer

我知道

std::vector <std::discrete_distribution <uint16_t> > distr(n, std::distribution <uint16_t> (v.begin(), v.end()) );

不正确,但我说的是将 v1 更改为 v. 以证明可以使用离散分布 vector

最佳答案

您可以使用列表初始化 来初始化嵌套 vector 。例如:

std::vector<std::vector<int>> v{
    {1, 2, 3},
    {4, 5, 6},
    {7, 8, 9}
};

关于c++ - 如何设置 "discrete_distribution"c++的 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48013802/

相关文章:

c# - 我的 VS 2013 应用程序应该包含哪个 C++ 合并模块

具有不同值类型模板参数的模板类的 C++ 数组或 vector

algorithm - 生成一个可以稍后验证的随机代码

c - C 中 rand() 的问题

c++ - 配置存储

C++:std::stack::pop() 方法的速度

c++ - 包含 <algorithm> 和 <limits> 会导致 "invalid pure specifier"编译错误

c++ - 根据 vector<bool> 修改 char 的位

c++ - 带有 std::vectors 的图形?

PHP、MySQL - 结果数组洗牌会比 "select... order by rand()"更快吗?