diag
- arrayfire.diag(array: Array, /, *, diag_index: int = 0, extract: bool = True) Array
Extract a diagonal from or create a diagonal matrix based on an input array.
This method operates on an ArrayFire array, allowing for the extraction of a specified diagonal from a 2-dimensional array or the creation of a diagonal matrix from a 1-dimensional array.
Parameters
- arrayArray
The input ArrayFire array. For diagonal extraction, this should be a 2-dimensional array. For diagonal matrix creation, this should be a 1-dimensional array.
- diag_indexint, optional, keyword-only, default: 0
The index of the diagonal that the operation pertains to. - diag_index == 0 signifies the main diagonal. - diag_index > 0 signifies a super diagonal. - diag_index < 0 signifies a sub diagonal.
- extractbool, optional, keyword-only, default: True
Determines the operation to perform: - If True, the method extracts the specified diagonal from a 2-dimensional array. - If False, the method creates a diagonal matrix with the input array populating the specified diagonal.
Returns
- Array
If extract is True, the returned Array contains the diag_index’th diagonal elements from the input array.
If extract is False, the returned Array is a diagonal matrix with the input array elements placed along
the diag_index’th diagonal.
Notes
The diag_index parameter allows for flexible selection of diagonals, enabling operations not just on the main diagonal but also on any super or sub diagonals relative to the main.