Note
Go to the end to download the full example code.
Row-wise Matrix Normalization Example#
Normalize each row of a matrix by dividing by its L2 norm.
Input matrix:
[[1 2 3]
[4 5 6]]
Row-wise normalized matrix normalize(x):
[[0.26726124 0.53452248 0.80178373]
[0.45584231 0.56980288 0.68376346]]
import numpy as np
from spheresmooth import normalize
# Example matrix (2 × 3)
x = np.array([
[1, 2, 3],
[4, 5, 6]
])
print("Input matrix:")
print(x)
# Row-wise normalization
x_norm = normalize(x)
print("\nRow-wise normalized matrix normalize(x):")
print(x_norm)