On Wed, Mar 26, 2008 at 09:48:02AM -0400, Pierre GM wrote:
All,
What's the quickest way to create a diagonal matrix ? I already have the
elements above the main diagonal. Of course, I could use loops:
m=5
z = numpy.arange(m*m).reshape(m,m)
for k in range(m):
for j in range(k+1,m):
If the rest of the matrix is already zeros and memory wasn't a
problem, you could just use
A_sym = A + A.T - diag(diag(A))
If memory was an issue, I'd suggest weave.inline (if that's a viable
option) or pyrex to do the loop, which would be about as fast as you
could get.
--Hoyt
On Wed, Mar