sumabs(A, dims)

sumabs(A, dims)

Sum absolute values of elements of an array over the given dimensions.

Examples

Sum the absolute values of elements in an array:

julia> arr = [-2, 4, -6, 8];
julia> sumabs(arr)
20

This example calculates the sum of the absolute values of all elements in the array arr.

Sum the absolute values of elements in a range:

julia> rng = -5:5;
julia> sumabs(rng)
30

It calculates the sum of the absolute values of all elements in the range -5:5.

Sum the absolute values of elements in a vector of complex numbers:

julia> complex_nums = [2 + 3im, -4 - 5im, 6 + 7im];
julia> sumabs(complex_nums)
29.0

This example calculates the sum of the absolute values of all elements in the vector of complex numbers.

Common mistake example:

julia> str = "Hello, Julia!";
julia> sumabs(str)
ERROR: MethodError: no method matching abs(::String)

In this example, the sumabs function cannot handle elements of type String since the abs function is not defined for strings. Ensure that the elements in the collection are of a type for which the abs function is defined.

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: