[Bioperl-l] Matrix Average Code / Module ?

Boris Steipe boris.steipe at utoronto.ca
Mon Feb 20 13:40:19 EST 2006


Assuming you mean the arithmetic average of all elements in a matrix,  
you could do the following (using your numbers):


#!/usr/bin/perl -w
use strict;

my @matrix;

push(@matrix, [(11,22,43,54,50)]); # [(...)] :a list passed as an  
anonymous array
push(@matrix, [(27,87,74,32,10)]);
push(@matrix, [(66,58,98,78,20)]);
push(@matrix, [(22,23,44,16,34)]);

my $sum = 0;
my $number = 0;

foreach my $row (@matrix) {
     foreach my $element (@{$row}){
         $sum += $element;
         $number++;
     }
}

print "Average of $number elements = ", $sum/$number,"\n";
exit;


HTH,

B.




On 20 Feb 2006, at 01:21, Shameer Khadar wrote:

> Hi all,
> Is there any program/module to calculate the average of a blosum/ 
> pam any
> matrix ?
>
> I have a matrix and I need to see the average
>
> for example
>
> 11 22 43 54 50
> 27 87 74 32 10
> 66 58 98 78 20
> 22 23 44 16 34
>
> I have gone through Bio::Matrix::MatrixI and  
> Bio::Matrix::GenericMatrix
> and other perl modules like Math::Matrix
> http://search.cpan.org/~ulpfr/Math-Matrix-0.4/Matrix.pm
> and Math::Cephes::Matrix - but none of them have a provison to do  
> matrix
> average calculation.
>
> Any help ???
> thanks in advance,
> Happy biocomputing !!!
>
>
> -- 
> Shameer Khadar
> National Centre for Biological Sciences (TIFR)
> UAS - GKVK Campus - Bellary Road Bangalore - 65 - Karnataka - India
> T - 91-080-23636420-32 EXT 4241
> F - 91-080-23636662/23636675
> W - http://www.ncbs.res.in
> --------------------------------------------------
> "Refrain from illusions, insist on work and not words,
>  patiently seek divine and scientific truth."
> MM
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l



More information about the Bioperl-l mailing list