The `transpose` function is problematic
See original GitHub issueThere are multiple problems, both related to adoption due to conflicting definitions, and because NumPy’s transpose
does something no one really wants (namely, swap all axes).
The current array API transpose
may not be correct:
- https://data-apis.org/array-api/latest/API_specification/linear_algebra_functions.html#transpose-x-axes-none says “swap all axes”
- https://github.com/data-apis/array-api/issues/147 claims the intent is to only swap the last two axes, to be consistent with all other
linalg
functions.
PyTorch names the numpy.transpose
equivalent permute
, and PyTorch’s transpose
is np.swapaxes
. Relevant issues PyTorch issues:
Relevant NumPy issues:
- https://github.com/numpy/numpy/issues/9530
- https://github.com/numpy/numpy/issues/7495
- https://github.com/numpy/numpy/issues/13797 (note that there’s
np.linalg.linalg.transpose
which is private but does have the desired behavior)
There’s multiple ways of dealing with this problem:
- Accept the status quo
- Remove
transpose
completely, and usepermute
or some other function name with the behavior we want by default (do the right thing for batches of 2-D matrices) - Add both, by adding a
matrix_transpose
function and a corresponding.mT
(or.MT
) attribute
I searched the JAX and TensorFlow issue trackers as well and, somewhat surprisingly, didn’t find an issue about this topic.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (7 by maintainers)
Top Results From Across the Web
How to correct a #VALUE! error in the TRANSPOSE function
Problem: The formula has not been entered as an array formula. Refer to the following example where we've used: =TRANSPOSE(B2:C8). #VALUE error in...
Read more >Solved! The problem with Excel Tables and Transpose
The Transpose() function would seem ideal because it works from a source Excel table. BUT, the result isn't an Excel table and can't...
Read more >google sheets - Problem using the TRANSPOSE() function
In an empty cell, I can use the function =TRANSPOSE(A1:A3) to get the rows switched into columns. My problem is that the three...
Read more >Data transpose function in R not working properly
My data is in rows and the columns are different variables. When using the function phyDat, the author indicates a transpose function because ......
Read more >TRANSPOSE formula problem
I'm not sure what I'm doing wrong, but I am trying to use the transpose formula to transpose row data to column headings...
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
I think separating the functionality of
np.transpose()
into two separate functions/methods would make sense. As you note, there are two distinct use cases:The only real relation is that (1) can be implemented via (2).
From my perspective, the functionality (1) would be the best fit for the name “transpose”, and (2) could use some other name, like “permute axes”.
permute_dims
seems quite reasonable too. If we consistently name keywordsaxis
/axes
, using_dims
for function names andndim
for attribute is at least some kind of consistency.