# mlx.core.eye — MLX 0.0.7 documentation

Skip to main content
`Ctrl`+`K`

# mlx.core.eye

mlx.core.eye(n: int, m: Optional[ int ] = None, k: int = 0, dtype: Optional[ Dtype ] = float32, *, stream: Union[ None , Stream , Device ] = None) → array

  Create an identity matrix or a general diagonal matrix.

  Parameters:

    - n (int) – The number of rows in the output.

    - m (int , optional) – The number of columns in the output. Defaults to n.

    - k (int , optional) – Index of the diagonal. Defaults to 0 (main diagonal).

    - dtype (Dtype , optional) – Data type of the output array. Defaults to float32.

    - stream (Stream , optional) – Stream or device. Defaults to None.

  Returns:

    An array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to one.

  Return type:

    array