[Numpy-discussion] How do I make a diagonal matrix?
Alan G Isaac
aisaac at american.edu
Fri Jun 23 11:03:13 CDT 2006
On Fri, 23 Jun 2006, Keith Goodman apparently wrote:
> my x is a Nx1 matrix. I can't get it to work with matrices.
Hmm. One would think that diag() would accept a flatiter
object, but it does not. Shouldn't it??
But anyway, you can squeeze x:
>>> x
matrix([[ 0.46474951],
[ 0.0688041 ],
[ 0.61141623]])
>>> y=N.diag(N.squeeze(x.A))
>>> y
array([[ 0.46474951, 0. , 0. ],
[ 0. , 0.0688041 , 0. ],
[ 0. , 0. , 0.61141623]])
hth,
Alan Isaac
More information about the Numpy-discussion
mailing list