If I am reading the Cookbook aright, you want to use the PDL module
from CPAN. For your example:
use PDL;
$foo = pdl [ 1, 2, 3 ];
$bar = pdl [ 4, 5, 6 ];
$baz = $foo + $bar;
I'm going to go verify this now, but it looks straightforward.
--TQuid | [reply] [d/l] |
I've not used them, but you might check out the Math::MatrixReal module and see if that's what you're looking for. From the documentation:"Also features many important operations and methods: matrix norm, matrix transposition, matrix inverse, determinant of a matrix, order and numerical condition of a matrix, scalar product of vectors, vector product of vectors, vector length, projection of row and column vectors, a comfortable way for reading in a matrix from a file, the keyboard or your code, and many more." --Chris | [reply] |
$baz = $foo x $bar;
(well, this actually won't work with TQuid's matrices, but
you get the point)
"test" | [reply] [d/l] |
In fact, x in PDL is overloaded to achieve matrix multiplication, so the left- and right-hand operands need to be appropriately dimensioned (it will error out in a hopefully-informative way if not). But * operates on an element-by-element basis (using "broadcasting") over vectors, thus achieving part of a dot-product (there is in fact an inner operation that does an actual dot-product).
| [reply] [d/l] [select] |
Perhaps Math::VecStat would suit your needs (I happened upon it while looking for a module for calculating primes).
It's description: "This package procides some basic statistics on numerical
vectors. All the subroutines can take a copy of the vector, or, preferably for efficiency, a reference to the vector to be operated on.
max(@vector), max(\@vector)
return the maximum value of given values or vector. In an array context returns the value and the index in the array where it occurs.
min(@vector), min(\@vector)
return the minimum value of given values or vector, In an array context returns the value and the index in the array where it occurs.
maxabs(@vector), maxabs(\@vector)
return the maximum value of absolute of the given values or vector. In an array context returns the value and the index in the array where it occurs.
minabs(@vector), minabs(\@vector)
return the minimum value of the absolute of the given values or vector, In an array context returns the value and the index in the array where it occurs.
sum($v1,$v2,...), sum(@vector), sum(\@vector)
return the sum of the given values or vector
average($v1,$v2,..), average(@vector), average(\@vector)
return the average of the given values or vector."
redmist | [reply] |