From: Alan G I. <ai...@am...> - 2006-07-28 23:17:30
|
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 |