Hi Gurunath,
Maybe I can help with the problem. I am not an expert at PDL either, but
here is how I would do it. I am supposing you have square matrices.
Suppose you have some pdl like below.
my $a = pdl([2,2,2],[3,1,0],[2,5,1]);
To find the diagonal you can use diagonal(0,1), where the arguments are
the dimensions to take the diagonal over.
my $b =$a ->diagonal(0,1);
print ("$a, $b\n");
Here is how you can take a sum of the diagonal
print (sumover($b),"\n");
Then you find the number of elements, assuming your matrices are square
you can take either of the two dimension, or otherwise use the nelem
function on the diagonal.
print ($b->dim(0),"\n");
You can do that in one step
print (sumover($a->diagonal(0,1))/$a->dim(0),"\n");
As for the standardeviation. You can calculate the variance as the
internal product of the diagonal minus the average.
my $b =- sumover($b)/$b->dim(0);
print ($b x transpose($b) );
I will leave you take the square root of that with sqrt();
Hope it helps, maybe somebody knows a faster way.
Regards, LouisOp zaterdag 26-05-2012 om 12:09 uur [tijdzone +0530],
schreef Gurunath Katagi:
> Dear all,
> I am new to using pdl ...
>
> i have some 30000 matrix from which i want to extract the diagonal
> elements from each of them and get the average and standard deviation
> of each of the diagonal elements among 30000 matrix.
>
> however, i am able to able to this in MATLAB, but its very slow ...
>
> Can anybody help to write this is program using pdl and is there
> anyway that i can process it fast using pdl ...
>
> my program goes like this :
> read the matrix files
> extract the diagnol elements from each of the them
> and find the avg. and std.
>
> I tried it, but i am facing problem with respect to extracting the
> diagonal elements...
>
>
> Thank you
> Gurunath
>
>
>
>
>
>
>
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl