Magnitude |z|
ShippingmagnitudeElement-wise modulus |z| = √(re² + im²) of a complex (or real) array
Signature
Inputs
zArray|Complex|Scalarrequired— Complex or real input. A real input yields |re| (absolute value).
Outputs
magnitudeArray— Real array of moduli, keeping z's physical unit.
Description
Magnitude |z| returns the element-wise modulus of a complex array: , computed per element with hypot for overflow-safe accuracy. The result is always a real array and keeps z's physical unit (the magnitude of a volt is a volt).
The node handles a real input gracefully by treating the imaginary part as zero, so on real data it simply returns the absolute value — making it a dual-purpose magnitude / abs helper. It is stateless.
Mathematics
Examples
Modulus of a phasor
Feeding gives (a 3-4-5 triangle). Feeding a real gives .
Magnitude spectrum
Wire a complex FFT output into z to obtain the amplitude spectrum directly.
Applications
- Computing the amplitude spectrum from a complex FFT result.
- Taking the envelope magnitude of an analytic (I/Q) signal.
- Using it as an absolute-value node on purely real data.
Neat
Uses f64::hypot per element rather than a naive √(r²+i²), so it stays accurate even when re or im is large enough to overflow the intermediate square.
The imaginary buffer is read directly from the structure-of-arrays layout — the node never routes through the real-only tensor wall that would reject complex values.