Jan. 31, 2008
1:47 a.m.
Say I have a matrix m whose diagonal values I want to replace with the contents of vector new_diagonal. Right now, I'm using m -= diag(m) m += diag(new_diagonal) but that seems pretty wasteful (especially if diag() creates new arrays, which I suspect it does). Is there a standard (or any efficient) way to assign the diagonal values directly without an explicit for loop? Googling for "site:www.scipy.org assign diagonal" only returned results for sparse matrices, which is not the case here - these are plain numpy arrays. Thanks in advance, -carlos