我如何在Perl中执行一些简单的矩阵运算 [英] How can i do some simple matrix operations in Perl

查看:469
本文介绍了我如何在Perl中执行一些简单的矩阵运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我已在Perlguru上发布了此内容,但尚未得到答复.
我只是希望能在这里得到一个.

无论如何,我在data.txt文件中有数据(数字).

我想导入它并将其用作矩阵.
即:只能在一行或一列上使用自然运算.并且或仅在一个元素上.

我已经尝试了一些方法:

1)我知道您可以创建一个像这样的矩阵:

Hello,

I posted this on Perlguru but, i have not gotten a reply yet.
I'' just hoping to get one here.

Anyway, i have data (numbers) in a file data.txt.

I would like to import it and use it as a matrix.
ie: be able to use a matematical operation on only one row, or only one column. And Or on only one element.

I have tried a few things:

1) I know you can create a matrix like this:

my @matrix1 = ( 
[qw(0 0 0 0)], 
[qw(0 0 1 0)], 
[qw(0 1 0 0)], 
[qw(1 0 0 0)], 
);



但是我一次只能访问一个元素.例如:$ matrix1 [0] [0]

2)我试图使用PDL :: Matrix模块.它给了我错误,但我没有在Google上找到解决方案.
我这样包含它:



But i can only access one element at a time. eg: $matrix1[0][0]

2) I have tried to use the PDL::Matrix module. It has given me errors, of which i have not found the solution on Google.
I included it like this:

use PDL::Matrix;



那条线没有给我任何错误. (我确实使用CPAN安装了它)

当我尝试像这样使用它时:



That line gave me no error. (I did install it, using CPAN)

When i tried to use it like this:

my $matrix2 = mpdl[[1,2,3],[4,5,6],[7,8,9]]; 
#or like this: 
my $matrix2 = pdl[[1,2,3],[4,5,6],[7,8,9]]; 
#or even like this: 
my $matrix2 = PDL::Matrix->pdl[[1,2,3],[4,5,6],[7,8,9]];





他们都给了我下面的错误:





All of them gave me the error below:

Can''t locate object method "pdl" via package "PDL::Matrix" at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/PDL/Matrix.pm line 134.




我一直在做两个例子进行练习,但是,我要执行的操作将导入我的文件,并且能够执行我上面描述的所有操作.我仍然必须弄清楚如何在文件处理程序中使用上述方法.
到目前为止,唯一有效的方法是导入文件并一次读取一行:(

感谢您的帮助




I have been doing the two examples for practice but, what i want to do it import my file and be able to do all the operations i described above. I still have to figure out how i will use the above method on my file handler.
The only thing that works so far is importing the file and reading one line at a time :(

Thank you for your help

推荐答案

matrix1 [0] [0]

2)我试图使用PDL :: Matrix模块.它给了我错误,但我没有在Google上找到解决方案.
我这样包含它:

matrix1[0][0]

2) I have tried to use the PDL::Matrix module. It has given me errors, of which i have not found the solution on Google.
I included it like this:

use PDL::Matrix;



那条线没有给我任何错误. (我确实使用CPAN安装了它)

当我尝试像这样使用它时:



That line gave me no error. (I did install it, using CPAN)

When i tried to use it like this:

my


matrix2 = mpdl [[1,2,3],[4,5,6],[7,8,9]]; #或像这样: my
matrix2 = mpdl[[1,2,3],[4,5,6],[7,8,9]]; #or like this: my


matrix2 = pdl [[1,2,3],[4,5,6],[7,8,9]]; #甚至像这样: 我的
matrix2 = pdl[[1,2,3],[4,5,6],[7,8,9]]; #or even like this: my


这篇关于我如何在Perl中执行一些简单的矩阵运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆