mlx.core.eye

Contents

mlx.core.eye#

eye(n: int, m: int | None = None, k: int = 0, dtype: Dtype | None = float32, *, stream: 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