diag_indices function issue?
See original GitHub issueHello there!
Is it ok that diag_indices function returns two links on one index array?
For example, I’m trying to use this function to acces not only to the main diagonal but also to the diagonal with the given offset (like using offset parameter in np.diagonal). To implement that I do something like this:
X = np.array(...) # some 2D array
n, m = X.shape # without loss of generality assume that n <= m
xi, yi = np.diag_indices(n)
yi += offset
xi, yi = xi[np.logical_and(yi < m,yi >= 0)], yi[np.logical_and(yi < m, yi >= 0)]
print(xi, yi) # print to check if values are different (they aren't)
print(xi is yi) # print to check out if instances are different (they aren't)
To fix this issue I suggest to do the following:
...
return list(arange(n) for i in range(ndim))
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
numpy.diag_indices() in Python - GeeksforGeeks
The numpy.diag_indices() function returns indices in order to access the elements of main diagonal of a array with minimum dimension = 2.
Read more >Diagonal< MatrixType, DiagIndex_ > Class Template Reference
DiagIndex, the index of the sub/super diagonal. The default is 0 and it means the main diagonal. A positive value means a superdiagonal,...
Read more >Given a multi-dimensional array, return an array containing ...
Create an initial array of numbers (for the diagonal sums) first, then use reduce to iterate, using the x index and y index...
Read more >mvst source: R/reparamT.R - RDRR.io
reparamT = function(N, p, particles){ # Reparameterization function n.pmat.indices.wo = p * (p-1) ... detOmega = numeric(N) detG = numeric(N) diagIndices ...
Read more >TLS-3XX Series Consoles - Troubleshooting Guide
CSLD Problem 3 - Increase Rate Warning for Manifolded Tanks 2 and 3 ... In-Tank Leak Result Diagnostic Function Diagram . ... consoles/diagindex.eps....
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 Free
Top 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

Note that
(np.arange(n),) * ndimis different in an important way from what you say there, in that only the tuple version works for indexing (without a deprecation warning).Agreed that this function is inconvenient though.
One thing we could do here is make the return value warn-on-write. Another would be to make the return value read-only.
I wonder if we can finally make
np.diagonalreturn a read-write view, so that the need for this function vanishes.Yeah, the diagonal thing has been warning since forever (at least it feels like it). I am happy with considering a full deprecation, or going the write-only/warn-on-write way. Going to the mailing list (best with a preferred/suggested choice maybe) sounds like a good idea.