medium framework

Apply Along an Axis

Normalize each row of a 2D matrix to sum to 1.0 (L1 normalization along axis 1).

For each row, divide every element by the sum of that row.

Input: A 2D tensor x of shape (m, n) with all positive values.

Output: A 2D tensor of the same shape where each row sums to 1.0.

API Reference:

  • PyTorch: x / x.sum(dim=1, keepdim=True)
  • JAX: x / x.sum(axis=1, keepdims=True)

Hints

normalization axis-operations keepdim broadcasting
Detecting runtime...