The following are from pyGAUSS.  
fwiw,
Alan Isaac

#diag: diagonal of matrix as column vector (2D only!)
def diag(x):
        if not isinstance(x,numpy.matrix):
                x = numpy.asanyarray(x)
                assert(len(x.shape)==2), "For 2-d arrays only."
                return x.diagonal(offset=0,axis1=-2,axis2=-1).reshape((-1,1))
        else:
                return x.diagonal().T

#diagrv: insert v as diagonal of matrix x (2D only!)
def diagrv(x,v,copy=True):
        x = numpy.matrix( x, copy=copy )
        stride = 1 + x.shape[1]
        x.flat[ slice(0,x.size,stride) ] = v
        return x



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to