将 PDL 标量转换为 Perl 标量
我有一个使用 PDL
的函数。最后一步是点积,因此它返回一个标量。然而,当我尝试打印这个标量时,它显然仍然是一个 piddle 并在屏幕上打印如下:
[
[ 3 ]
]
我想知道如何将其转换回常规 Perl 标量,以便它打印如下:
3
更重要的是,什么是如果我不转换并将该 piddle 在纯 Perl 上下文(不涉及 PDL)中进行进一步的算术操作,则会产生后果。谢谢!
I have a function that uses PDL
. The final step is a dot product so it returns a scalar. However, when I try to print this scalar, it is clearly still a piddle and prints like this on screen:
[
[ 3 ]
]
I'm wondering how I can convert it back to the regular Perl scalar so that it prints like:
3
More importantly, what is the consequence if I don't convert and take that piddle on to further arithmetic manipulations in a pure Perl context (that does not involve PDL). Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
sclr
方法,将任意维数的单元素 PDL 矩阵转换为简单的 Perl 标量Use the
sclr
method, which converts a single-element PDL matrix with any number of dimensions into a simple Perl scalar回答第二个问题(“如果我不转换并在纯 Perl 上下文(不涉及 PDL)中使用该 piddle 进行进一步的算术操作,会产生什么后果”);有两个主要考虑因素:
$dotp->squeeze
删除所有长度为 1 的暗淡To answer the second question ("what is the consequence if I don't convert and take that piddle on to further arithmetic manipulations in a pure Perl context (that does not involve PDL)"); there are two major considerations:
$dotp->squeeze
to drop all length-1 dims