Xtensor random :: randn返回的数字低于下限和上方的上限
我正在尝试生成随机数的形状{10},范围在-0.5和0.5之间,
#include <iostream>
#include <xtensor/xio.hpp>
#include <xtensor/xrandom.hpp>
int main() {
xt::xarray<double> a = xt::random::randn<double>({10}, -0.5, 0.5);
std::cout << a;
return 0;
}
但它返回一个数组
{-0.432735, -0.573191, -0.269675, -1.435692, -0.418144, -0.607127,
-0.350702, -0.913972, -0.494892, 0.027733}
,其中-0.573191较小,-1.435692大于范围。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 :
该函数从 您将平均值设置为
-0.5
,标准偏差为0.5
。这些不是下限和上限。您可能需要使用 函数:
这是从 - 因此,它不是同一件事,但它具有较低和上限。
According to the documentation for
randn
:The function draws numbers from
std::normal_distribution
and you've set the mean value to be-0.5
and the standard deviation to be0.5
. These are not lower and upper bounds.You may want to use the
rand
function instead:This draws numbers from
std::uniform_real_distribution
- so, it's not the same thing, but it has a lower and an upper bound.