incrementing along a diagonal

Johannes Loehnert a.u.r.e.l.i.a.n at gmx.net
Wed Oct 11 03:35:32 CDT 2006


> I'm just wondering if there is a way that i can increment all the values
> along a diagonal?

Assume you want to change mat.

# min() only necessary for non-square matrices
index = arange(min(mat.shape[0], mat.shape[1]))
# add 1 to each diagonal element
matrix[index, index] += 1
# add some other stuff
matrix[index, index] += some_array_shaped_like_index


HTH, Johannes

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Numpy-discussion mailing list