Let the vector $\ell = \begin{pmatrix} \ell_1 \\ \ell_2 \\ \vdots \\ \ell_p \end{pmatrix}$, and the goal is to find a matrix which returns $\psi = \dfrac{\ell_1+\ell_2+\cdots+\ell_q}{\ell_1+\ell_2+\cdots+\ell_p}$, where $q \leq p.$
Is there any matrix $M$ such that $\ell M = \psi$?
Of course not, a matrix/vector product is always linear.
Using dot products with vector $1_k$ of $k$ ones followed by $p-k$ zeroes,
$$\psi=\frac{1_q\cdot\ell}{1_p\cdot\ell}.$$
Anyway, you can work with homogeneous coordinates, i.e. pairs $(u,v)$ such that $(u,v)\equiv(\lambda u,\lambda v)$ for any $\lambda\ne0$ and write
$$(u,v)=\ell\,[1_q\ 1_p]^T$$ and
$$(u,v)\equiv(\psi,1).$$