in reply to Calculate log of matrix values

The log function is not defined for 0. You can check for zeros in the loop:
$lnpam[$i][$j] = log $matrix[$i][$j] if $matrix[$i][$j];

The resulting matrix would have undefined values in the corresponding places.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Calculate log of matrix values
by madM (Beadle) on Aug 09, 2013 at 14:08 UTC
    i solved the problem using this:
    LINE: for (my $i=0; $i<20; $i++){ for (my $j=0; $j<20; $j++){ if ($matrix[$i][$j] =~ /[^0.00]/){ $lnpam[$i][$j] = log $matrix[$i][$j]; }else{ next LINE; } } }
    thanks a lot for the quick answer!
      if ($matrix[$i][$j] =~ /[^0.00]/){

      This does not do what you think it does, but it is at least close. You are really only doing if ($matrix[$i][$j] =~ /[^0.]/){ IE: does the string have at least one character that is not a literal '0' or a '.'

      See: Bracketed Character Classes

      Why not make the test if ($matrix[$i][$j] > 0)? That's much simpler and faster, and will not fail on "-0.00 " or " 0.00" or regular negative numbers.

        thanks! you are right :)