Matrix and vector norms for mlx arrays
Arguments
- x
An mlx array.
- ord
Numeric or character norm order. Use
NULLfor the default 2-norm.- axes
Integer vector of axes (1-indexed). Supply positive integers between 1 and the array rank. Many helpers interpret
NULLto mean "all axes"—see the function details for specifics.- drop
If
TRUE(default), drop dimensions of length 1. IfFALSE, retain all dimensions. Equivalent tokeepdims = TRUEin underlying mlx functions.
Examples
x <- mlx_matrix(1:4, 2, 2)
mlx_norm(x)
#> mlx array []
#> dtype: float32
#> device: gpu
#> values:
#> [1] 5.477226
mlx_norm(x, ord = 2)
#> mlx array []
#> dtype: float32
#> device: gpu
#> values:
#> [1] 5.464986
mlx_norm(x, axes = 2)
#> mlx array [2]
#> dtype: float32
#> device: gpu
#> values:
#> [1] 3.162278 4.472136