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

Alan G Isaac alan.isaac at gmail.com
Sat Jan 3 12:54:27 EST 2015


> 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.

Cheers,
Alan




More information about the NumPy-Discussion mailing list