[Numpy-discussion] What is diagonal for nd>2?
Sasha
ndarray at mac.com
Thu Apr 6 12:42:17 EDT 2006
It looks like the definition of the diagonal changed somewhere between
Numeric 24.0 and numpy:
In Numeric:
>>> x = Numeric.arange(2*4*4)
>>> x = Numeric.reshape(x, (2, 4, 4))
>>> x
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]],
[[16, 17, 18, 19],
[20, 21, 22, 23],
[24, 25, 26, 27],
[28, 29, 30, 31]]])
>>> Numeric.diagonal(x)
array([[ 0, 5, 10, 15],
[16, 21, 26, 31]])
But in numpy:
>>> import numpy as Numeric
>>> x = Numeric.arange(2*4*4)
>>> x = Numeric.reshape(x, (2, 4, 4))
>>> Numeric.diagonal(x)
array([[ 0, 20],
[ 1, 21],
[ 2, 22],
[ 3, 23]])
The old logic seems to be clear: x is a pair of matrices and diagonal
returns a pair of diagonals, but the new logic seems unclear: the disagonal
returns the first rows of the two matrices transposed.
Does anyone know when this change was introduced and why?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060406/484624d2/attachment.html>
More information about the NumPy-Discussion
mailing list