fill_diagonal#
- class saiunit.math.fill_diagonal(a, val, wrap=False, inplace=False)#
Fill the main diagonal of the given array of any dimensionality.
For an array
awitha.ndim >= 2, the diagonal is the list of locations with indicesa[i, i, ..., i]all identical.- Parameters:
a (saiunit.Quantity |
Array|ndarray|bool|number|bool|int|float|complex) – Array in which to fill the diagonal.val (saiunit.Quantity |
Array|ndarray|bool|number|bool|int|float|complex) – Value to be written on the diagonal. Its unit must be compatible with that ofa.wrap (
bool|None) – IfTrue, the diagonal is “wrapped” aftera.shape[1]and continues in the first column (for tall matrices). Default isFalse.inplace (
bool|None) – IfTrue, the diagonal is filled in-place. Default isFalse.
- Returns:
out – The input array with the diagonal filled.
- Return type:
saiunit.Quantity |
Array
Examples
>>> import saiunit as u >>> import jax.numpy as jnp >>> u.math.fill_diagonal(jnp.zeros((3, 3)), 5.0) Array([[5., 0., 0.], [0., 5., 0.], [0., 0., 5.]], dtype=float32)