[SciPy-user] Newbie type questions

Pearu Peterson pearu at scipy.org
Wed Aug 6 03:38:06 EDT 2003


On Tue, 5 Aug 2003, Jeffrey B. Layton wrote:

> Hello,
> 
>    I've played with Scipy off and on for a few months, but now
> I need to get serious. I am co-authoring an engineering book
> and will have a large number of examples in it. We are already
> using MATLAB (and Octave), but I have convinced my
> co-authors and perhaps the publishers to put Python/Scipy in
> there as well. This text is a graduate level text and the models
> in the book can be quite large and time-consuming.
>    Towards this, we have an appendix where we explain the basics
> of MATLAB and Octave for those who need to brush up or who
> need a  quick intro (enough to run the examples). I'm writing the
> companion appendix for Python/Scipy. So, I'm working through
> the examples. This leads me to my questions
>    If I declare a complex matrix A,
> 
> A=array([[complex(1,1),complex(2,2)],[complex(3,3),complex(4,4)]])

A shorter Matrix version of that would be

  from scipy import *
  A=mat([[1+1j,2+2j],[3+3j,4+4j]])

> and I want to take the transpose, which I'm assuming to be the
> complex conjugate, I need to type
> 
> AT=transpose(conjugate(A))
> 
> to get the actual complex conjugate. Is there an easier way to do this?

Yes, using mat from scipy, yo can do

  AT = A.H

For instance,

>>> A.H
Matrix([[ 1.-1.j,  3.-3.j],
       [ 2.-2.j,  4.-4.j]])

>    A somewhat related question, if I declare a vector X,
> 
> X=array([1,2,3])
> 
> and then try to take the transpose of it,
> 
> Y=transpose(X)
> 
> then X=Y.

This is true when using array.

> I sort of understand this since the shape of X
> is (3, ). Shouldn't the shape of X be (3,1)?

Again, try mat:

>>> X=mat([1,2,3])
>>> Y = X.T
>>> X
Matrix([       [1, 2, 3]])
>>> Y
Matrix([[1],
       [2],
       [3]])
>>> X.shape
(1, 3)
>>> Y.shape
(3, 1)

HTH,
	Pearu




More information about the SciPy-User mailing list