How do I efficiently set the diagonal elements of a >= 2 dimensional NumPy array?
In recent Subversion versions of NumPy (and in the upcoming release of NumPy 1.4.0) you can use the fill_diagonal function. The source code of the function is in index_tricks.py if you'd rather use it now; just copy and paste it.
fill_diagonal
Tags:
numpy ✕13 array ✕1 diagonal ✕1
Asked: 2 years, 9 months ago
Seen: 3,148 times
Last updated: 2 years, 9 months ago
Setting the diagonal values of an array
How do I get random numbers in numpy?
Plotting data
What is the relationship between numpy and scipy?
Identification of block diagonal matrices
What's the difference between numpy.linalg and scipy.linalg?
Is numpy.random a pseudorandom number generator or real random?
Efficient "inside polygon" test for an array?
How to build numpy/scipy on Ubuntu or Debian
How do you install numpy/scipy with ATLAS support on a machine with non-root access?