Perl PDL是否有办法将向量夹在另一个向量中给出的最小值/最大值而不会迭代?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pdl :: prientive :: primitive :: Hclip
:PDL::Primitive::hclip
is for this: