series_magnitude

This page explains how to use the series_magnitude function in APL.

The series_magnitude function calculates the Euclidean norm (magnitude) of a numeric dynamic array (series). This computes the square root of the sum of squared elements, representing the length or magnitude of the vector.

You can use series_magnitude when you need to measure the overall magnitude of a series, compare vector lengths, normalize data, or calculate distances in multi-dimensional space. This is particularly useful in signal processing, similarity analysis, and feature scaling for machine learning applications.

Usage

Syntax

series_magnitude(array)

Parameters

ParameterTypeDescription
arraydynamicA dynamic array of numeric values.

Returns

A numeric scalar representing the Euclidean norm (magnitude) of the series, calculated as the square root of the sum of squared elements.

Use case examples

In log analysis, you can use series_magnitude to calculate the overall load magnitude from multiple request duration measurements, creating a single metric representing total system stress.

Query

['sample-http-logs']
| summarize durations = make_list(req_duration_ms) by ['geo.city']
| extend load_magnitude = series_magnitude(durations)
| project ['geo.city'], load_magnitude
| order by load_magnitude desc

Run in Playground

Output

geo.cityload_magnitude
Seattle325.5 ms
Portland285.2 ms
Denver245.8 ms

This query calculates the magnitude of request duration vectors for each city, providing a single metric that represents the overall load intensity.

In OpenTelemetry traces, you can use series_magnitude to compute a composite performance metric that captures the overall latency footprint of each service.

Query

['otel-demo-traces']
| extend duration_ms = duration / 1ms
| summarize durations = make_list(duration_ms) by ['service.name']
| extend performance_magnitude = series_magnitude(durations)
| project ['service.name'], performance_magnitude
| order by performance_magnitude desc

Run in Playground

Output

service.nameperformance_magnitude
checkout1250.5
frontend895.3
cart650.2

This query computes a magnitude metric for each service's latency profile, helping prioritize optimization efforts for services with the highest overall latency impact.

In security logs, you can use series_magnitude to calculate an overall threat intensity score based on multiple security metrics, creating a composite risk indicator.

Query

['sample-http-logs']
| summarize request_metrics = make_list(req_duration_ms) by status
| extend threat_magnitude = series_magnitude(request_metrics)
| project status, threat_magnitude
| order by threat_magnitude desc

Run in Playground

Output

statusthreat_magnitude
4012850.5 ms
5001250.3 ms
200425.8 ms

This query calculates the magnitude of request patterns for each HTTP status code, providing a single metric that represents the overall intensity of potentially concerning traffic.

  • series_sum: Returns the sum of all values. Use when you need simple addition instead of Euclidean norm.
  • series_abs: Returns absolute values of elements. Often used before magnitude calculation to handle negative values.
  • series_pearson_correlation: Computes correlation between series. Use when measuring similarity instead of magnitude.
  • series_stats: Returns comprehensive statistics. Use when you need multiple measures instead of just magnitude.

Other query languages