Perl 中的矩阵矩阵
在我正在处理的 Perl 脚本中,我需要用其他几个矩阵构建一个矩阵。 我查看了 CPAN 中的几个模块(数学: :矩阵,PDL::矩阵, Math::Cephes::Matrix< /a>),但这些似乎都不支持这一点。
在 Octave 中,这非常容易。 这是一个与我想做的事情类似的例子:
octave:1> A = [ 1, 2; 3, 4 ]
A =
1 2
3 4
octave:2> B = [ 5, 6; 7, 8 ]
B =
5 6
7 8
octave:3> C = [ 9, 10; 11, 12 ]
C =
9 10
11 12
octave:4> D = [ 13, 14; 15, 16 ]
D =
13 14
15 16
octave:5> E = [ A, B; C, D ]
E =
1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16
似乎自己尝试这样做会很快变得混乱,这可能就是为什么这些模块不支持它的原因......还有其他人有过这样的经历吗?需要这个吗? 你解决了吗?
In a Perl script I'm working on, I need to build a matrix out of several other matrices. I've looked at a couple of modules in CPAN (Math::Matrix, PDL::Matrix, Math::Cephes::Matrix), but none of these seem to support this.
In Octave, this is very easy. Here's an example of something similar to what I'm trying to do:
octave:1> A = [ 1, 2; 3, 4 ]
A =
1 2
3 4
octave:2> B = [ 5, 6; 7, 8 ]
B =
5 6
7 8
octave:3> C = [ 9, 10; 11, 12 ]
C =
9 10
11 12
octave:4> D = [ 13, 14; 15, 16 ]
D =
13 14
15 16
octave:5> E = [ A, B; C, D ]
E =
1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16
It seems trying to do this myself would get messy kinda quickly, which is probably why these modules don't support it... Has anyone else out there ever had a need for this? Have you solved it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
自己滚动并不太痛苦。
Rolling your own isn't too painful.
Perl 数据语言 (PDL) 版本 2.4.10 支持
pdl 构造函数,以及
append
和glue
例程可用于将子数组粘贴在一起,如pdl2
会话所示: a href="http://pdl.perl.org/content/pdl-book-toc.html" rel="nofollow">PDL 书 和 PDL 邮件列表是有关 PDL 的更多信息的重要来源。
The Perl Data Language (PDL) version 2.4.10 supports MATLAB-style convenience input for the
pdl
constructor when using a string argument and theappend
andglue
routines can be used to paste subarrays together as thispdl2
session shows:The PDL book and the PDL mailing lists are essential sources for more information on PDL.
编辑
我误解了OP,认为他们想要迭代几个矩阵的所有可能的排列(这就是 Iterator::Array::Jagged 所做的)。
看看 Iterator::Array::Jagged
这是一个概要示例:
上面代码中的示例打印以下内容:
EDIT
I misunderstood the OP, thinking that they wanted to iterate over all possible permutations of several matrices (which is what Iterator::Array::Jagged does).
Take a look at Iterator::Array::Jagged
Here is an example from the synopsis:
The example in the code above code prints the following: