Travis has introduced the function diagflat for creating diagonal arrays. It flattens whatever array is supplied and returns its values as the diagonal of a 2-D array or matrix. As the function is currently undocumented I thought now might be a good time to discuss other possible choices for the name. Here is a quick list that comes to mind diagflat (current name) asdiagonal todiagonal asdiag todiag ... Chuck
On Sun, 3 Sep 2006 12:20:09 -0600 "Charles R Harris" <charlesr.harris@gmail.com> wrote:
Travis has introduced the function diagflat for creating diagonal arrays. It flattens whatever array is supplied and returns its values as the diagonal of a 2-D array or matrix. As the function is currently undocumented I thought now might be a good time to discuss other possible choices for the name. Here is a quick list that comes to mind
diagflat (current name) asdiagonal todiagonal asdiag todiag ...
Chuck
+1 for todiag Nils
On 03/09/06, Charles R Harris <charlesr.harris@gmail.com> wrote:
Travis has introduced the function diagflat for creating diagonal arrays. It flattens whatever array is supplied and returns its values as the diagonal of a 2-D array or matrix. As the function is currently undocumented I thought now might be a good time to discuss other possible choices for the name. Here is a quick list that comes to mind
diagflat (current name) asdiagonal todiagonal asdiag todiag ...
I was wishing for that just the other day... I think my vote is for "diagflat", to emphasize the initial flattening. In particular, there's another function I could wish for: given an array, pick an axis, treat the array like an array of vectors along that axis, and replace each vector with the diagonal matrix. So, supposing that it was called todiagonal:
A = todiagonal(ones(2,3,4),axis=1) shape(A) (2,3,3,4) A[1,:,:,2] array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
Specifically I find the forcible flattening a bit monstrous. And you can always just do todiagonal(A.flat). No such function seems to exist at the moment, so I'm attaching one; probably not as efficient as it could be with appropriate fancy indexing wizardry. A. M. Archibald
participants (3)
-
A. M. Archibald
-
Charles R Harris
-
Nils Wagner