Diagonal function
Warning
This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.
Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.
Namespace: Microsoft.Quantum.Arrays
Package: Microsoft.Quantum.Standard
Returns an array of diagonal elements of a 2-dimensional array
function Diagonal<'T> (matrix : 'T[][]) : 'T[]
Description
If the 2-dimensional array has not a square shape, the diagonal over the minimum over the number of rows and columns will be returned.
Input
matrix : 'T[][]
2-dimensional matrix in row-wise order
Output : 'T[]
Type Parameters
'T
The type of each element of matrix
.
Example
let matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
let diagonal = Diagonal(matrix);
// same as: column = [1, 5, 9]
See Also
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for