KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'd like to do arithmetics with k-th diagonal of a numpy.array. I need those indices. For example, something like: >>> a = numpy.eye(2) >>> a[numpy.diag_indices(a, k=-1)] = 5 >>> a array([[ 1., 0.], [ 5., 1.]]) Unfortunately, diag_indices only returns the indices comprising the main diagonal, so at the moment I am doing: a += numpy.diag([5], -1) But that doesn't seem as nice or robust. :-) Is there a way in numpy to get indices for other than the main diagonal?
Tags (comma-separated)
Save Edits
Cancel