![](https://secure.gravatar.com/avatar/95198572b00e5fbcd97fb5315215bf7a.jpg?s=120&d=mm&r=g)
1 Jul
2009
1 Jul
'09
2:38 p.m.
On Wed, Jan 30, 2008 at 10:28 PM, Anand Patil<anand.prabhakar.patil@gmail.com> wrote:
Yeah, that's awesome. I have so many for-loops littering my code for setting diagonals. Here's an nd-version:
def setdiag(a, d): assert(all([s == len(d) for s in a.shape])) stride = 1+sum(cumprod(a.shape[:-1])) a.flat[::stride] = d
If someone feels like reviewing this ticket: http://projects.scipy.org/numpy/attachment/ticket/1132/numpy-index-funcs.dif... it has the above and a few more utilities, with docs and tests. Cheers, f