[Numpy-discussion] big picture? One proposal

Perry Greenfield perry at stsci.edu
Fri Mar 8 07:12:11 EST 2002


Pearu Peterson writes:

[...]
> 
> I find separating array and matrix instances (in a sense of raising
> exception when doing <matrix> <op> <array>) not a very simple solution:
>   New concepts are introduced that actually do not solve the simplicity
> problem of representing matrix operations. As I see it, they
> only introduce restrictions and the main assumption behind the rationale
> is that "users are dumb and they don't know what is best for them".
> This is how I interpret the raised exception as behind the scenes matrix
> and array are the same (in the sense of data representation). 
> 
I don't think the issue is whether users are "dumb" but rather, will it
be more or less transparent to them what is supposed to happen. Remember,
this particular proposal affects in no way the notational convenience
when operands are of the same type. It doesn't even affect the notational
convenience of most of the examples presented (e.g., a.M * b.M) as
long as the resulting operands are of the same type. It only affects
cases involving mixed types. Do we really want 

<matrix> * <array>   (yes, it would be possible to have one dominate over
<array> * <matrix>    the other always regardless of order)

to mean two different things for example? Will a user always be aware
that a module function returns arrays rather than matrices. Yes, users
ought to check the documentation, but they often don't or they 
misremember. The more I think about it the more I come to think it
really is better to be safer in this case. It will not be hard
for users to explicitly convert, nor should it be notationally
cumbersome. E.g. (just to use one the proposed options)

matrix(a) * b
a * array(b)

I don't see this as a big burden. I would rather do it this way myself
for my own code.

[...]
> (there have been two implementation approaches proposed for this: (i) a.M
> returns a Matrix instance, (ii) a.M returns the same array with a
> temporarily set bit saying that the following operation is somehow
> special).
> To me, this looks like a safe solution. Though it is a hack, at least it
> is simple and understandable in anywhere where it is used (having a * b
> where b can be either matrix or array, it is not predictable from just
> looking the code what the result will be -- not very pythonic indeed).
>
It's safer, but it isn't safe. Besides, one could still do this and raise
exceptions on mixed types. Is the issue that people strongly want to do
(if both a an b are arrays)

a.M * b  (or matrix(a) * b)

instead 

a.M * b.M (or matrix(a) * matrix(b))

to get matrix behavior?
 
Perry
 




More information about the NumPy-Discussion mailing list