mlx.core.diagonal#
- diagonal(a: array, offset: int = 0, axis1: int = 0, axis2: int = 1, stream: None | Stream | Device = None) array#
Return specified diagonals.
If
ais 2-D, then a 1-D array containing the diagonal at the givenoffsetis returned.If
ahas more than two dimensions, thenaxis1andaxis2determine the 2D subarrays from which diagonals are extracted. The new shape is the original shape withaxis1andaxis2removed and a new dimension inserted at the end corresponding to the diagonal.- 參數:
a (array) -- 輸入陣列
offset (int, optional) -- Offset of the diagonal from the main diagonal. Can be positive or negative. Default:
0.axis1 (int, optional) -- The first axis of the 2-D sub-arrays from which the diagonals should be taken. Default:
0.axis2 (int, optional) -- The second axis of the 2-D sub-arrays from which the diagonals should be taken. Default:
1.
- 回傳值:
The diagonals of the array.
- 回傳值型別: