[SciPy-user] Mathematica Element-wise Multiplication
Stefan van der Walt
stefan at sun.ac.za
Mon Dec 17 14:04:56 EST 2007
On Sun, Dec 16, 2007 at 11:49:38PM -0800, Johann Cohen-Tanugi wrote:
> Matthieu Brucher wrote:
> >
> >
> > 2007/12/17, Johann Cohen-Tanugi <cohen at slac.stanford.edu
> > <mailto:cohen at slac.stanford.edu>>:
> >
> > thanks for these precisions, David. Reading it, I still come to think
> > that it is a potential source of confusion to let a "row array" have a
> > transpose or T method, that essentially does nothing.
> >
> >
> >
> > In object oriented code, this can happen often, but it is not a
> > problem. It does what you want : inverse the axis, even if there is
> > only one axis.
> hmmm...... okay... What I wanted was to transpose a 1D array into a
> vector, or vice-versa, with the linear algebra behavior in mind. I
> understand that numpy does not follow this, but I cannot believe that
> this behavior *is* what everybody wants! Tom's initial email was
> symptomatic, and Stefan's response, with the proposal to use the T
> method even more so!
I'm not sure what my response was symptomatic of, but if you don't
like the behaviour of ndarrays, you may consider using 'matlib':
In [1]: from numpy import matlib
In [2]: x = matlib.matrix([1,2,3])
In [3]: x
Out[3]:
matrix([[1, 2, 3]])
In [4]: x.T
Out[4]:
matrix([[1],
[2],
[3]])
In [5]: x * x.T
Out[5]:
matrix([[14]])
> Assuming that this natural linear algebra could be retrieved when, and
> *only* when, the array is 1D, I do not see how such an implementation
> could break codes that depend on it, because I don't see why someone
> would call 'a.T' just to have 'a' again.... But it is probably my lack
> of imagination.
When I call "transpose", I don't expect an array to change dimensions.
Like Matthieu wrote, it swaps the axes, and if you have only one axis
there is nothing to swap. Start with a two-dimensional array, and the
transpose will do what you expect.
Regards
Stéfan
More information about the SciPy-User
mailing list