[Numpy-discussion] Quikest way to create a diagonal matrix ?

Pierre GM pgmdevlist@gmail....
Wed Mar 26 08:48:02 CDT 2008

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:
>>>z = numpy.arange(m*m).reshape(m,m)
>>>for k in range(m):
>>>    for j in range(k+1,m):
>>>        z[j,k] = z[k,j]
But I was looking for something more efficient.
Thanks a lot in advance !

More information about the Numpy-discussion mailing list