Indexing.pod (PDL-2.078) | : | Indexing.pod (PDL-2.079) | ||
---|---|---|---|---|

skipping to change at line 1251 | skipping to change at line 1251 | |||

usage of the former: | usage of the former: | |||

[ # ** this is the worst possible example to start with ] | [ # ** this is the worst possible example to start with ] | |||

# but can be used to show that $mat += $line is different from | # but can be used to show that $mat += $line is different from | |||

# $mat->broadcast(0) += $line | # $mat->broadcast(0) += $line | |||

# explicit broadcasting to add a vector to each column of a matrix | # explicit broadcasting to add a vector to each column of a matrix | |||

pdl> $mat = zeroes(4,3) | pdl> $mat = zeroes(4,3) | |||

pdl> $line = pdl (3.1416,2,-2) | pdl> $line = pdl (3.1416,2,-2) | |||

pdl> ($tmp = $mat->broadcast(0)) += $line | pdl> ($tmp = $mat->broadcast(0)) += $line | |||

In this example, C<$mat-E<gt>broadcast(0)> tells PDL that you want the second | In this example, C<< $mat->broadcast(0) >> tells PDL that you want the second | |||

dimension of this ndarray to be broadcast over first leading to a broadcast | dimension of this ndarray to be broadcast over first leading to a broadcast | |||

loop that can be expressed as | loop that can be expressed as | |||

for (j=0; j<3; j++) { | for (j=0; j<3; j++) { | |||

for (i=0; i<4; i++) { | for (i=0; i<4; i++) { | |||

mat(i,j) += src(j); | mat(i,j) += src(j); | |||

} | } | |||

} | } | |||

C<broadcast> takes a list of numbers as arguments which explicitly | C<broadcast> takes a list of numbers as arguments which explicitly | |||

End of changes. 1 change blocks. | ||||

1 lines changed or deleted | | 1 lines changed or added |