diagonal

Contents

diagonal#

class brainunit.linalg.diagonal(a, offset=0, axis1=0, axis2=1, **kwargs)#

Return specified diagonals.

Parameters:
  • a (Array | saiunit.Quantity) – Array from which the diagonals are taken.

  • offset (int) – Offset of the diagonal from the main diagonal. Can be positive or negative. Defaults to main diagonal (0).

  • axis1 (int) – Axis to be used as the first axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to first axis (0).

  • axis2 (int) – Axis to be used as the second axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to second axis (1).

Returns:

res – The extracted diagonals. The shape of the output is determined by considering the shape of the input array with the specified axis removed.

Return type:

Array | saiunit.Quantity

Examples

>>> import saiunit as u
>>> a = [[1, 2], [3, 4]] * u.second
>>> u.math.diagonal(a)