R/081_atoms_harmonic_mean.R

Defines functions harmonic_mean

Documented in harmonic_mean

#####
## DO NOT EDIT THIS FILE!! EDIT THE SOURCE INSTEAD: rsrc_tree/atoms/harmonic_mean.R
#####

## CVXPY SOURCE: atoms/harmonic_mean.py
## HarmonicMean -- n / sum(1/x_i)

#' Harmonic mean: n / sum(1/x_i)
#'
#' @param x An Expression (must be positive for DCP)
#' @returns An Expression representing the harmonic mean
#' @export
harmonic_mean <- function(x) {
  x <- as_expr(x)
  expr_size(x) * p_norm(x, p = -1)
}

Try the CVXR package in your browser

Any scripts or data that you put into this service are public.

CVXR documentation built on March 6, 2026, 9:10 a.m.