[SciPy-user] Mathematica Element-wise Multiplication

Travis E. Oliphant oliphant@enthought....
Wed Dec 19 19:50:20 CST 2007


Erik Volz wrote:
> There are several aspects of scipy that are counterintuitive to 
> typical users. Tranpose of 1D arrays is a big one. Another example is
> z+=z.T # where dimension z > 1
> which does not do what a naive user would think it does (try it).
>
> I recently introduced very damaging bugs into my code by making both 
> of these mistakes; it took a long time for me to track down the 
> problem. Of course, the behavior is very logical from a developer's 
> perspective, but the veterans of this list have been very 
> unsympathetic. At a minimum, there should be warnings in the 
> doc-strings about this behavior.

Yes, absolutely, warnings should be there in the docstring.  Your 
perspective is not illogical nor are many of us unsympathetic to it.   
But,  following your rule would be an "exceptional" case  to an 
otherwise easy to explain rule. 

Our approach thus far has been to educate users coming from other 
languages that there is such a thing as a 1D array that is neither a 
"row" nor a "column" vector and so in fact a transpose operation is not 
really what you meant (as it does nothing to a 1D array).   Instead what 
you wanted to do was convert the 1-D array to a 2-D array with 1 row and 
then transpose that to a 2D array with 1 column.  

Doing this "automatically" for you is assuming a particular convention 
which we at least try not to do that  often.  The problems it causes, 
come down to introducing oddities in code that could otherwise work over 
arbitrary dimensions.

Finding the right balance between least-surprise and rule-exception 
headaches is not an easy one (nor will I ever claim that NumPy has made 
all the right choices).  Because NumPy is community developed, there is 
always the possibility that the behavior will change.  Of course, after 
something has come into use, it needs more of an argument than 
subjective points about a typical user (although I like hearing those 
kinds of suggestions when deciding what a *new* or *revamped* thing 
should do).  

Thanks for sharing your perspective.  I'm very aware that for every 
piece of "negative" feedback (and yours really wasn't) there are 100 
people who feel the same way but don't have the time to tell us.   I'm 
very sorry to hear of the bugs you couldn't find because of this 
mis-communication in the .T attribute.

Best regards,

-Travis Oliphant




More information about the SciPy-user mailing list