# [SciPy-user] simple question about digonal matrices

Gary Ruben gazzar at email.com
Tue May 11 08:25:19 CDT 2004

```Hi Karthik,
FYI, there's a numpy discussion list here <http://lists.sourceforge.net/lists/listinfo/numpy-discussion> which is probably a more appropriate place to post a numpy-specific question.

As for your problem, here's one way to do it:

>>> from numarray import *
>>> D = array([1,2,3])
>>> D_with_zeros = array([[0,0,0],
[0,0,0],
[0,0,0]])
>>> where(identity(3),D,D_with_zeros)
array([[1, 0, 0],
[0, 2, 0],
[0, 0, 3]])

HTH,
Gary Ruben

----- Original Message -----
From: Karthikesh Raju <karthik at james.hut.fi>
Date: Tue, 11 May 2004 12:26:21 +0300
To: scipy-user at scipy.net
Subject: [SciPy-user] simple question about digonal matrices

> Hi All,
>
> How does one do something as mundane as assigning value to a diagonal
> vector.
>
> D = array([1,2,3])
>
> D_with_zeros = array([[0,0,0],
>                      [0,0,0],
>                      [0,0,0]])
>
> now i want D in the diagonal of D_with_zeros, i was trying something like:
> numarray.diagonal(D_with_zeros) = D
>
> numarray is not happy with my assignment?
>
> Warm regards
> karthik

--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm

```

More information about the SciPy-user mailing list