[Numpy-discussion] degree matrix construction

Satya Upadhya satyaupadhya at yahoo.co.in
Fri Sep 15 09:09:25 EDT 2006


Dear Friends,
my question is the following:

Suppose i have the following code:

>>> from LinearAlgebra import *

>>> from Numeric import *
>>> A = [1,2,1,3,1,3,4,1,2]
>>> B = reshape(A,(3,3))
>>> C = sum(B,1)
>>> C
array([4, 7, 7])
>>> 

Now, my problem is to construct a degree matrix D which is a 3 * 3 matrix with diagonal elements 4,7,7 (obtained from the elements of C) and all off-diagonal elements equal to 0.
Could some kind soul kindly tell me how to do this.
I've looked at the help for the diagonal function and i am unable to do what i wish to. Furthermore i dont understand the meaning of axis1 and axis2:
>>> help (diagonal)
Help on function diagonal in module Numeric:

diagonal(a, offset=0, axis1=0, axis2=1)
    diagonal(a, offset=0, axis1=0, axis2=1) returns all offset diagonals
    defined by the given dimensions of the array.

>>>

Thanking you,
Satya




 				
---------------------------------
 Find out what India is talking about on  - Yahoo! Answers India 
 Send FREE SMS to your friend's mobile from Yahoo! Messenger Version 8. Get it NOW
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060915/2b020246/attachment.html>


More information about the NumPy-Discussion mailing list