Dear oshalla,
Thank you so much for your reply.
It is truly useful.
I also tried to modify your code to do
multiplication of
transpose of the sparse matrix.
With the following code:
use Data::Dumper;
my @realval = (
0.994704478,
0.989459074,
0.994717023,
1.000000000,
1.000000000,
0.002647761,
0.005282977,
0.000882587,
0.005270463,
0.000882587,
0.002635231,
0.000882587,
0.002635231,);
my @row_index = qw( 1 2 3 4 5 1 3 1 2 1 2 1 2);
my @col_index = qw(1 2 3 4 5 5 3 2 1 3 3 4 4);
my @mat_dim = (5,5); # M always equal to N
my @trans_r = (0) x scalar(@p);
for my $j (0..$#row_index) {
$trans_r[$col_index[$i]-1] += $realval[$i] * $p[$row_index[$i]-1] ;
}
print Dumper \@trans_r;
Not sure why it doesn't give this desired result:
@result = (0.3989359, 0.1982448, 0.2008801, 0.2008801, 0.2010591);
Truly need your expert advice on this. Thanks and hope to hear from you again.
---
neversaint and everlastingly indebted.......
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.