[SciPy-user] assign to diagonal values?

Fernando Perez fperez.net@gmail....
Wed Jul 1 14:38:12 CDT 2009

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:


it has the above and a few more utilities, with docs and tests.



More information about the SciPy-user mailing list