upper
- arrayfire.upper(array: Array, /, *, is_unit_diag: bool = False) Array
Extract the upper triangular part of a given multi-dimensional ArrayFire array.
This function returns the upper triangular matrix from the input array. If the is_unit_diag flag is set to True, the diagonal elements are considered to be all ones, and therefore not explicitly stored in the output.
Parameters
- arrayArray
The input ArrayFire array from which to extract the upper triangular part. This array must be at least 2-dimensional.
- is_unit_diagbool, optional, keyword-only, default: False
A flag that specifies whether the diagonal elements of the upper triangular matrix are to be considered as 1. If True, the diagonal elements are assumed to be 1, and thus not explicitly included in the output array. If False, the diagonal elements are taken as they appear in the input array.
Returns
- Array
An ArrayFire array containing the upper triangular part of the input array. If is_unit_diag is True, the diagonal elements are considered to be 1 but are not explicitly included in the array.
Notes
The function does not alter the elements below the main diagonal; it simply does not include them in the output.
- This function can be useful for mathematical operations that require upper triangular matrices,
- such as certain types of matrix factorizations.
Examples
>>> import arrayfire as af >>> a = af.randu((3, 3)) # Generate a random 3x3 array >>> a [3 3 1 1] 0.8962 0.6105 0.7896 0.3712 0.5232 0.8966 0.6755 0.5567 0.0536
>>> af.upper(a) # Extract upper triangular part without unit diagonal [3 3 1 1] 0.8962 0.6105 0.7896 0.0000 0.5232 0.8966 0.0000 0.0000 0.0536
>>> af.upper(a, is_unit_diag=True) # Extract upper triangular part with unit diagonal [3 3 1 1] 1.0000 0.6105 0.7896 0.0000 1.0000 0.8966 0.0000 0.0000 1.0000