Just select a subset by using indexing (in the following example: classic python-based slicing; but more complex indexing / numpy-style is possible):

Example:

from cvxpy import *

x = Variable(5)
constraints = []
constraints.append(x >= 0)   # all vars
constraints.append(x <= 10)  # all vars
constraints.append(sum_entries(x[:3]) <= 3)  # only part of vector; sum(first-three) <=3
objective = Maximize(sum_entries(x))
problem = Problem(objective, constraints)
problem.solve()
print(problem.status)
print(x.value.T)

Output:

optimal
[[  1.   1.   1.  10.  10.]]

Note: as of cvxpy 1.0, sum_entries has been changed to sum

I also suspect you are misunderstanding the problem here, but that formula-image is of course incomplete to be implemented.

Answer from sascha on Stack Overflow
🌐
Cvxpy
cvxpy.org › tutorial › functions › index.html
Atomic Functions -
The functions max and min give ... and minimum to find the max or min of a list of scalar expressions. The CVXPY function sum sums all the entries in a single expression....
🌐
Cvxpy
cvxpy.org › api_reference › cvxpy.atoms.affine.html
Affine Atoms -
class cvxpy.cumsum(expr: Expression, axis: None | int = 0)[source]¶ ... Cumulative sum of the elements of an expression.
🌐
Cvxpy
cvxpy.org › examples › basic › least_squares.html
Least-squares -
In a least-squares, or linear regression, problem, we have measurements \(A \in \mathcal{R}^{m \times n}\) and \(b \in \mathcal{R}^m\) and seek a vector \(x \in \mathcal{R}^{n}\) such that \(Ax\) is close to \(b\). Closeness is defined as the sum of the squared differences: \[\sum_{i=1}^m (a_i^Tx ...
🌐
Snyk
snyk.io › advisor › cvxpy › functions › cvxpy.sum
How to use the cvxpy.sum function in cvxpy | Snyk
cvxgrp / cvxportfolio / cvxportfolio / policies.py View on Github · t : pd.timestamp Timestamp for the optimization. """ if t is None: t = dt.datetime.today() value = sum(portfolio) w = portfolio / value z = cvx.Variable(w.size) # TODO pass index wplus = w.values + z if isinstance(self.return_forecast, BaseReturnsModel): alpha_term = self.return_forecast.weight_expr(t, wplus) else: alpha_term = cvx.sum(cvx.multiply( values_in_time(self.return_forecast, t).values, wplus)) assert(alpha_term.is_concave()) costs, constraints = [], [] for cost in self.costs: cost_expr, const_expr = cost.weight_expr(t, wplus, z, value) costs.append(cost_expr) constraints += const_expr constraints += [item for item in (con.weight_expr(t, wplus, z, value) for con in self.constraints)] for el in costs:
🌐
Readthedocs
ajfriendcvxpy.readthedocs.io › en › latest › tutorial › intro
What is CVXPY? — CVXPY 0.2.25 documentation
Use the CVXPY function sum_entries to sum the entries of a single CVXPY matrix or vector expression.
🌐
Readthedocs
ajfriendcvxpy.readthedocs.io › en › latest › tutorial › functions
Functions — CVXPY 0.2.25 documentation - Read the Docs
The input to bmat is a list of lists of CVXPY expressions. It constructs a block matrix. The elements of each inner list are stacked horizontally and then the resulting block matrices are stacked vertically. The output \(y\) of conv(c, x) has size \(n+m-1\) and is defined as \(y[k]=\sum_{j=0}^k c[j]x[k-j]\).
🌐
Cvxpy
cvxpy.org › _modules › cvxpy › atoms › affine › sum.html
cvxpy.atoms.affine.sum -
""" import builtins from functools ... AxisAtom from cvxpy.constraints.constraint import Constraint class Sum(AxisAtom, AffAtom): """Sum the entries of an expression over a given axis....
🌐
Cvxpy
cvxpy.org › _modules › cvxpy › atoms › sum_squares.html
cvxpy.atoms.sum_squares -
See the License for the specific ... sum_squares( expr, axis: Optional[Union[int, Tuple[int, ...]]] = None, keepdims: bool = False ): """The sum of the squares of the entries....
Find elsewhere
🌐
Cvxpy
cvxpy.org › _modules › cvxpy › atoms › affine › cumsum.html
cvxpy.atoms.affine.cumsum -
""" def __init__(self, expr: Expression, axis: int = 0) -> None: super(cumsum, self).__init__(expr, axis) @AffAtom.numpy_numeric def numeric(self, values): """ Returns the cumulative sum of elements of an expression over an axis.
🌐
Cvxpy
cvxpy.org › tutorial › advanced › index.html
Advanced Features -
# create a 3-dimensional variable (locations, days, hours) x = cp.Variable((12, 10, 24)) constraints = [ cp.sum(x, axis=(0, 2)) <= 2000, # constrain the daily usage across all locations x[:, :, :12] <= 100, # constrain the first 12 hours of each day at every location x[:, 3, :] == 0,] # constrain the usage on the fourth day to be zero obj = cp.Minimize(cp.sum_squares(x)) prob = cp.Problem(obj, constraints) prob.solve() Please refer to NumPy’s excellent reference on N-dimensional arrays and the array API standard for more details on how to manipulate N-dimensional arrays. Our goal is to match the NumPy API as closely as possible. ... N-dimensional support is still experimental and may not work with all CVXPY features.
🌐
GitHub
github.com › cvxpy › cvxpy › issues › 1784
cp.sum is inconsistent with np.ndarray · Issue #1784 · cvxpy/cvxpy
May 23, 2022 - To Reproduce cp.sum(npasarray([1,2,3,cp.Variable(),4,5]))
Published   May 23, 2022
Author   michael-123123
🌐
Cvxpy
cvxpy.org › _modules › cvxpy › atoms › sum_largest.html
cvxpy.atoms.sum_largest -
December 3, 2022 - """ from typing import Tuple import numpy as np import scipy.sparse as sp import cvxpy.interface as intf from cvxpy.atoms.atom import Atom · [docs] class sum_largest(Atom): """ Sum of the largest k values in the expression X """ def __init__(self, x, k: int) -> None: self.k = k super(sum_largest, self).__init__(x) def validate_arguments(self) -> None: """Verify that k is a positive integer.
🌐
Snyk
snyk.io › advisor › cvxpy › functions › cvxpy.sum_entries
How to use the cvxpy.sum_entries function in cvxpy | Snyk
def Hawkes_log_lik(T, alpha_opt, lambda_opt, lambda_ti, survival, for_cvx=False): L = 0 for i in range(len(lambda_ti)): if for_cvx and len(lambda_ti) > 0: L += CVX.sum_entries(CVX.log(lambda_opt + alpha_opt * lambda_ti[i])) else: L += np.sum(np.log(lambda_opt + alpha_opt * lambda_ti[i])) L -= lambda_opt * T[i] + alpha_opt * survival[i] return L
🌐
Cvxpy
cvxpy.org › updates › index.html
Changes to CVXPY — CVXPY 1.5 documentation
Adds methods to CVXPY expressions that are found on NumPy ndarrays such as .sum(), .max(), and .mean()