Implement matrix normalization that can normalize along different axes using different norm types.
L2 Norm (Euclidean)
∣∣x∣∣2=i∑xi2L1 Norm (Manhattan)
∣∣x∣∣1=i∑∣xi∣Max Norm (Infinity)
∣∣x∣∣∞=imax∣xi∣matrix: 2D array-like inputaxis: 0 (column-wise), 1 (row-wise), or None (entire matrix)norm_type: 'l1', 'l2', or 'max'Input: [[3,4],[1,0]], axis=1, norm_type='l2'
Output: [[0.6, 0.8], [1.0, 0.0]]
Row-wise L2: [3,4] → [3/5, 4/5], [1,0] → [1,0]
Input: [[1,2],[3,4]], axis=0, norm_type='l1'
Output: [[0.25, 1/3], [0.75, 2/3]]
Column-wise L1: col1: [1,3] → [1/4, 3/4], col2: [2,4] → [2/6, 4/6]
Input: [[2,8],[4,2]], axis=1, norm_type='max'
Output: [[0.25, 1.0], [1.0, 0.5]]
Row-wise Max: [2,8] → [2/8, 8/8], [4,2] → [4/4, 2/4]
Use NumPy's built-in functions like np.sum(), np.sqrt(), and np.max() with the axis parameter. Remember to use keepdims=True for proper broadcasting during division.
Sign in to take notes on this problem
Accepts: array
Accepts: any
Accepts: string
Implement matrix normalization that can normalize along different axes using different norm types.
L2 Norm (Euclidean)
∣∣x∣∣2=i∑xi2L1 Norm (Manhattan)
∣∣x∣∣1=i∑∣xi∣Max Norm (Infinity)
∣∣x∣∣∞=imax∣xi∣matrix: 2D array-like inputaxis: 0 (column-wise), 1 (row-wise), or None (entire matrix)norm_type: 'l1', 'l2', or 'max'Input: [[3,4],[1,0]], axis=1, norm_type='l2'
Output: [[0.6, 0.8], [1.0, 0.0]]
Row-wise L2: [3,4] → [3/5, 4/5], [1,0] → [1,0]
Input: [[1,2],[3,4]], axis=0, norm_type='l1'
Output: [[0.25, 1/3], [0.75, 2/3]]
Column-wise L1: col1: [1,3] → [1/4, 3/4], col2: [2,4] → [2/6, 4/6]
Input: [[2,8],[4,2]], axis=1, norm_type='max'
Output: [[0.25, 1.0], [1.0, 0.5]]
Row-wise Max: [2,8] → [2/8, 8/8], [4,2] → [4/4, 2/4]
Use NumPy's built-in functions like np.sum(), np.sqrt(), and np.max() with the axis parameter. Remember to use keepdims=True for proper broadcasting during division.
Sign in to take notes on this problem
Accepts: array
Accepts: any
Accepts: string