roofline.devPublic Beta

L1 Norm

0EASYPracticeReport issue

Compute the L1 norm of each row of a matrix.

Given a matrix XX of shape n×mn \times m stored in row-major order, compute a vector YY of length nn such that each element is the L1 norm of the corresponding row:

Yi=jmXi,jY_i = \sum_{j}^{m} \lvert X_{i,j} \rvert

Input

  • X — input matrix of shape n×mn \times m stored in row-major order.
  • n — number of rows in X.
  • m — number of columns in X.

Output

  • Y — output vector of length n, where each element Y[i] is the L1 norm of row i of X.
Open on a desktop browser to write and submit code.

Public submissions

Practice problem · every submission below is public, click to view code