---
title: "matrix_diagonal"
url: https://una-lang.org/en/docs/std/prelude/matrix_diagonal/
release: v0.4.0
edition: "0.5 preview"
source: https://github.com/una-lang/una/blob/v0.4.0/docs/std/listing.json
---

# matrix_diagonal

A function of the prelude, in scope in every module. Edition 0.5 preview.

```una
pub matrix_diagonal[T](values: Array[T]) -> Matrix[T]
  ensures result.rows == values.len and result.columns == values.len
```

The square matrix with `values` on its diagonal and `+0` of the element type elsewhere (`spec/29 §17`). O(n²).

## Specification

- [`spec/29 §17`](https://una-lang.org/en/docs/spec/29-numerics/17-dense-values/#s17)

Generated from the standard modules of una v0.4.0 ([`docs/std/listing.json`](https://github.com/una-lang/una/blob/5fec93d88932b333feec25e589355a2cb34c37b5/docs/std/listing.json), which is not part of the specification). The specification governs: [`spec/14 §1`](https://una-lang.org/en/docs/spec/14-standard-library/#s1).
