sumabs2!

sumabs2!(r, A)

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

Examples

  1. Calculate sum of squared absolute values for a vector:

    julia> r = zeros(3);
    julia> A = [1, -2, 3];
    julia> sumabs2!(r, A)
    3-element Array{Float64,1}:
    14.0
    0.0
    0.0

    This example calculates the sum of squared absolute values of the elements in vector A and stores the results in vector r.

  2. Calculate sum of squared absolute values for a matrix along rows:

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

    It calculates the sum of squared absolute values of the elements in matrix A along each row and stores the results in vector r.

  3. Calculate sum of squared absolute values for a tensor along specified dimensions:
    julia> r = zeros(2);
    julia> A = [1 2 3; -4 -5 -6; 7 8 9];
    julia> sumabs2!(r, A, dims=(1, 2))
    2-element Array{Float64,1}:
    285.0
    0.0

    It calculates the sum of squared absolute values of the elements in tensor A along dimensions 1 and 2 and stores the results in vector r.

Common mistake example:

julia> r = [10, 20, 30];
julia> A = [1, -2, 3];
julia> sumabs2!(r, A)
ERROR: MethodError: no method matching sumabs2!(::Array{Int64,1}, ::Array{Int64,1})

In this example, the input arrays r and A have different element types (Int64 and Float64). Ensure that the types of the arrays match to avoid such errors.

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: