sumabs!

sumabs!(r, A)

Sum absolute values of elements of A over the singleton dimensions of r, and write results to r.

Examples

  1. Calculate sum of absolute values along singleton dimensions:

    julia> A = [1, -2, 3, -4, 5];
    julia> r = zeros(5);
    julia> sumabs!(r, A)
    5-element Array{Float64,1}:
    1.0
    2.0
    3.0
    4.0
    5.0

    This example calculates the sum of absolute values of each element in A along the singleton dimensions (in this case, along the first dimension) and stores the results in the array r.

  2. Calculate sum of absolute values along multiple singleton dimensions:

    julia> A = [1 -2; 3 -4; 5 -6];
    julia> r = zeros(2);
    julia> sumabs!(r, A)
    2-element Array{Float64,1}:
    9.0
    12.0

    Here, the sumabs! function calculates the sum of absolute values along the columns of A (singleton dimension 1) and stores the results in the array r.

  3. Modify existing array with sum of absolute values:
    julia> A = [1, -2, 3, -4, 5];
    julia> sumabs!(A, A)
    5-element Array{Int64,1}:
    1
    2
    3
    4
    5

    In this example, the sumabs! function modifies the existing array A by replacing its elements with the sum of their absolute values.

Common mistake example:

julia> A = [1 -2 3; 4 -5 6];
julia> r = zeros(2);
julia> sumabs!(r, A)
ERROR: DimensionMismatch("dimensions must match")

This error occurs when the dimensions of r and A do not match. Ensure that the dimensions of r are compatible with the singleton dimensions of A to avoid this mistake.

See Also

abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: