Perl PDL是否有办法将向量夹在另一个向量中给出的最小值/最大值而不会迭代?

发布于 2025-02-07 04:45:00 字数 672 浏览 2 评论 0原文

pdl 已经有一种方法可以将“夹紧”向量元素“夹紧”向量元素到另一个向量中给出的最小值/最大值?我已经浏览了 pdl :: Math选项。

我可以unddl/re pdl ,但这似乎太多了。

是否已经有一种矢量方法来做到这一点?

我尝试了这样的事情:

$pdl = pdl [4.45, 5.55, 45];
$max = pdl [2   , 3,    50];
print ( (($max <=> $pdl) > 0)*$pdl + (($max <=> $pdl) < 0)*$max ) 
[2 3 45]

它似乎有效,但表达真是太疯狂了。有内置吗?

Does PDL already have a way to "clamp" vector elements to min/max values given in another vector? I've looked through the PDL::Math documentation but didn't see a good candidate option.

I could unpdl/re-pdl but that seems like too much overhead.

Is there already a vectorized way to do this?

I tried something like this:

$pdl = pdl [4.45, 5.55, 45];
$max = pdl [2   , 3,    50];
print ( (($max <=> $pdl) > 0)*$pdl + (($max <=> $pdl) < 0)*$max ) 
[2 3 45]

which seems to work, but what a crazy expression. Is there a built-in for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽月 2025-02-14 04:45:00

pdl :: prientive :: primitive :: Hclip

pdl> $pdl = pdl [4.45, 5.55, 45];
pdl> $max = pdl [2   , 3,    50];
pdl> p $pdl->hclip($max)
[2 3 45]

PDL::Primitive::hclip is for this:

pdl> $pdl = pdl [4.45, 5.55, 45];
pdl> $max = pdl [2   , 3,    50];
pdl> p $pdl->hclip($max)
[2 3 45]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文