[Consistency] Default axes in `linalg.diagonal` and `linalg.trace`.
See original GitHub issueThe functions linalg.trace
and linalg.diagonal
have as default axis1=0, axis2=1
.
This goes against the rest of the documentation, in which a batch of matrices is defined as a tensor with shape (..., M, N)
.
It would be more consistent with the rest of the API to have axis1=-2, axis2=-1
to handle batches of matrices correctly by default.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5 (5 by maintainers)
Top Results From Across the Web
numpy.trace — NumPy v1.24 Manual
Axes to be used as the first and second axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults are...
Read more >Lecture 1: Intro/refresher in Matrix Algebra
I is a square diagonal matrix, with all diagonal elements being one, all off-diagonal elements zero. I ij. = 1 for i =...
Read more >Geometric interpretation of trace - linear algebra
-when a matrix A is in diagonal form, the trace is really the integral of its eigenvalues with the counting measure. -you can...
Read more >Linear Algebra (scipy.linalg) — SciPy v1.9.3 Manual
This function takes a rank-1 (vectors) or a rank-2 (matrices) array and an optional order argument (default is 2). Based on these inputs,...
Read more >What is the definition of a trace of a tensor?
We are aware of the trace of a two-dimensional tensor i.e. matrix. It is defined as the sum of the diagonal elements of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Fixed by gh-241, which removes the keywords. Thanks @Lezcano and @leofang
Wouldn’t it be better to just remove
axis1
andaxis2
entirely and always use the last two axes? This makes it more consistent with other linalg APIs, and is mathematically more intuitive. Users who need to compute trace/diagonal along arbitrary two axes can always swap the axes (related: #228) first before calling the API.