[SciPy-user] Mathematica Element-wise Multiplication

Johann Cohen-Tanugi cohen at slac.stanford.edu
Mon Dec 17 11:30:20 EST 2007


hi Brian,
point well taken. Thank you! I definitely use array more than I should then.
best,
Johann

Brian Blais wrote:
>
> On Dec 17, 2007, at Dec 17:2:49 AM, Johann Cohen-Tanugi wrote:
>
>> Matthieu Brucher wrote:
>>>
>>>
>>> 2007/12/17, Johann Cohen-Tanugi <cohen at slac.stanford.edu 
>>> <mailto: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.
>
> if you have linear algebra in mind, then you can use a matrix...it 
> works the way you expect:
>
> In [1]:from numpy import *
>
> In [2]:a=array([1,2,3,4])
>
> In [3]:a.shape
> Out[3]:(4,)
>
> In [4]:b=a.T
>
> In [5]:b.shape
> Out[5]:(4,)
>
> In [6]:a=matrix([1,2,3,4])
>
> In [7]:a.shape
> Out[7]:(1, 4)
>
> In [8]:b=a.T
>
> In [9]:b.shape
> Out[9]:(4, 1)
>
> In [10]:a
> Out[10]:matrix([[1, 2, 3, 4]])
>
> In [11]:b
> Out[11]:
> matrix([[1],
>         [2],
>         [3],
>         [4]])
>
>
>
>
> bb
> -- 
> Brian Blais
> bblais at bryant.edu <mailto:bblais at bryant.edu>
> http://web.bryant.edu/~bblais <http://web.bryant.edu/%7Ebblais>
>
>
>




More information about the SciPy-User mailing list