--- id: geometric_mean_py_datascience name: geometric_mean kind: function lang: py domain: datascience version: "1.0.0" purity: pure signature: "def geometric_mean(values: list[float]) -> float" description: "Geometric mean of positive elements via exp(mean(log(x))). Non-positive values are filtered out. Returns math.nan if no positives." tags: [statistics, mean, geometric, distribution, lognormal] uses_functions: [] uses_types: [] returns: [] returns_optional: false error_type: "" imports: [math, numpy] example: | from geometric_mean import geometric_mean result = geometric_mean([1, 2, 4, 8]) # ~2.828 (2^1.5) tested: true tests: - "test_geometric_mean_powers_of_two" - "test_geometric_mean_filters_non_positive" - "test_geometric_mean_empty_returns_nan" - "test_geometric_mean_all_negative_returns_nan" - "test_geometric_mean_single_positive" test_file_path: "python/functions/datascience/tests/test_geometric_mean.py" file_path: "python/functions/datascience/geometric_mean.py" params: - name: values desc: "List of numeric values. Non-positive elements are silently ignored." output: "Geometric mean as float, computed over positive elements only. Returns math.nan if there are no positive values." source_repo: "internal:footprint_aurgi" source_license: "internal-aurgi" source_file: "aurgi_mapas/generar_pdf_reporte.py:126" --- ## Ejemplo ```python from geometric_mean import geometric_mean geometric_mean([1, 2, 4, 8]) # 2.828... (= 2^1.5) geometric_mean([1, -2, 3]) # exp((log(1)+log(3))/2) — ignores -2 geometric_mean([]) # math.nan geometric_mean([-1, -2]) # math.nan — no positives ``` ## Notas Apropiado para distribuciones lognormales o datos multiplicativos (precios, ratios, crecimientos). Equivalente a la raiz n-esima del producto pero numericamente mas estable via log-space.