[Numpy-discussion] What is diagonal for nd>2?

Sasha ndarray at mac.com
Thu Apr 6 14:46:10 EDT 2006


I see. However, something needs to be changed.  In the current version
help(diagonal) prints the following:
{{{
Help on function diagonal in module numpy.core.oldnumeric:

diagonal(a, offset=0, axis1=0, axis2=1)
    diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals
    defined by the last two dimensions of the array.
}}}

I would think axes 0 and 1 are the first, not the last two dimensions.  We
can either change the documentation or change the defaults in the
oldnumeric.  I would vote for the change in defaults because oldnumeric is a
compatibility module and should not introduce changes.

In addition, the fact that the reduced axes become the first (rather than
the last or one of the axis1 and axis2) dimension should be spelled out in
the docstring.



On 4/6/06, Pierre GM <pgmdevlist at mailcan.com> wrote:
>
> > Does anyone know when this change was introduced and why?
>
> Isn't it more a problem of default values ?
> By default, x.diagonal() == x.diagonal(0,0,1)
>
> x.diagonal()
> array([[ 0, 20],
>        [ 1, 21],
>        [ 2, 22],
>        [ 3, 23]])
>
> If you want the paired diagonal:
> x.diagonal(0,1,-1)
> array([[ 0,  5, 10, 15],
>        [16, 21, 26, 31]])
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060406/6a4b894f/attachment.html>


More information about the NumPy-Discussion mailing list