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

Matthieu Brucher matthieu.brucher@gmail....
Wed Mar 26 09:14:47 CDT 2008


Hi,

Did you try diag() ? Or are you saying a symmetric matrix ?

Matthieu

2008/3/26, Pierre GM <pgmdevlist@gmail.com>:
>
> 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):
> >>>        z[j,k] = z[k,j]
> But I was looking for something more efficient.
> Thanks a lot in advance !
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080326/0f519157/attachment.html 


More information about the Numpy-discussion mailing list