Converting Complex Values in an Array to their Absolute Value (Magnitude)

This seems like it should be straight forward, but I’m not seeing much …
I have a 2D array A of complex values, but I need an array of its absolute values (magnitude). I naively write, B = abs(A), but of course, it does not work.
This is simple, right?

Try

B = abs.(A)

Here the . is used for broadcasting, see Multi-dimensional Arrays · The Julia Language

Edit: see also the simpler Functions · The Julia Language

2 Likes

Does

abs.(A)

do the trick?

1 Like

Yes! Thank you.