[Numpy-discussion] diag, diagonal, ravel and all that

Charles R Harris charlesr.harris at gmail.com
Sat Jan 3 13:51:54 EST 2015


On Sat, Jan 3, 2015 at 10:54 AM, Alan G Isaac <alan.isaac at gmail.com> wrote:

> > On Sat, Jan 3, 2015 at 8:05 AM, Alan G Isaac wrote:
> >>     Would this really be practicality beating purity?
> >>     It would be nice to have know the principle governing this.
> >>     For example, is there a way to convincingly group these as
> >>     array operations vs matrix operations?
> >>     Personally I am puzzled by preserving subtype of
> >>     `diagonal` and
> >>     very especially of `ravel`.  Has anyone requested this?
> >>     (I can see the argument for `diag`.)
>
>
>
> On 1/3/2015 10:32 AM, Charles R Harris wrote:
> > In [1]: from astropy import units as u
>
> > In [2]: a = eye(2) * u.m
>
> > In [3]: a
> > Out[3]:
> > <Quantity [[ 1., 0.],
> >             [ 0., 1.]] m>
>
> > In [4]: diagonal(a)
> > Out[4]: <Quantity [ 1., 1.] m>
>
> > In [5]: diag(a)
> > Out[5]: <Quantity [ 1., 1.] m>
>
> > In [6]: ravel(a)
> > Out[6]: <Quantity [ 1., 0., 0., 1.] m>
>
> > None of those examples keep the units without the recent changes.
>
>
>
> Thanks for a nice example.  It seems that the core principle
> you are proposing is that design considerations generally
> require that subtypes determine the return types of numpy
> functions. If that is correct, then it seems matrices should
> then be subject to this; more special casing of the behavior
> of matrix objects seems highly undesirable


I would agree with you, except that the changes breaks code that uses
matrices because matrices are always 2-d whereas the previous results were
1-d. If it were a few not widely used projects I'd stick with it, but
scipy.sparse is one of the packages that is broken. Numpy/scipy are not
released together, and numpy is often used to compile older versions of
scipy, so breaking scipy is undesirable. Becaus we are hoping to phase
matrices out over time, preserving the old behavior for matrices until we
can dispense with them looks to be the easiest solution.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150103/0f32ee7d/attachment.html>


More information about the NumPy-Discussion mailing list