neversaint has asked for the wisdom of the Perl Monks concerning the following question:
Then I would like to capture the following information from there:2 3 0 0 0 3 0 4 0 6 0 -1 -3 2 0 0 0 1 0 0 0 4 2 0 1
use strict; use warnings; my (@Ax, @Ai, @Ap) = (); while (<>) { chomp; my @elements = split /\s+/; my $i = 0; my $new_line = 1; while (defined(my $element = shift @elements)) { $i++; if ($element) { push @Ax, 0 + $element; if ($new_line) { push @Ai, scalar @Ax; $new_line = 0; } push @JA, $i; } } } push @Ai, 1 + @Ax; print('@Ax = [', join(" ", @Ax), "]\n"); print('@Ai = [', join(" ", @Ai), "]\n"); print('@Ap = [', join(" ", @Ap), "]\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capturing Non-Zero Elements, Counts and Indexes of Sparse Matrix
by gone2015 (Deacon) on Aug 25, 2009 at 09:06 UTC | |
|
Re: Capturing Non-Zero Elements, Counts and Indexes of Sparse Matrix
by BioLion (Curate) on Aug 25, 2009 at 09:36 UTC | |
|
Re: Capturing Non-Zero Elements, Counts and Indexes of Sparse Matrix
by BrowserUk (Patriarch) on Aug 25, 2009 at 15:19 UTC |