[Tutor] Unity matrix

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Tue Sep 28 23:21:54 CEST 2004



On Tue, 28 Sep 2004, Stuart Murdock wrote:

> Does anyone know if there is a builtin to numarray (or an add on ) to
> give me a unity matrix. It would look better than trying to add ones
> along the diagonal of a zeros.

Hi Stuart,


You're probably looking for the identity() function:

###
>>> numarray.identity(5)
array([[1, 0, 0, 0, 0],
       [0, 1, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 0, 1, 0],
       [0, 0, 0, 0, 1]])
###

Numarray has extensive documentation --- you can find more information on
the array-generating functions here:

    http://stsdas.stsci.edu/numarray/Doc/node22.html#l2h-36



More information about the Tutor mailing list