From: Tim H. <tim...@ie...> - 2001-03-14 17:15:17
|
From: "Aureli Soria Frisch" <Aur...@ip...> > Hi, > > It seems there is a problem when multiplying complex arrays, but maybe that > is already solved for the new NumPy 17.3, is it? > > The product of complex arrays does not seem to be right. > > Code lines: > > >>> a=a_conj[:] This is your problem here. Array's differ from lists and such in that slicing does not produce a copy. 'a' and 'a_conj' point to the same data after this operation. One way to produce a copy is to use 'a = Numeric.array(a_conj)' > >>> a > array([[ 1.-0.j, 1.-1.j, 1.-2.j], > [ 1.-3.j, 1.-4.j, 1.-5.j], > [ 1.-6.j, 1.-7.j, 1.-8.j]]) > >>> a.imag=a.imag*-1 > >>> a > array([[ 1.+0.j, 1.+1.j, 1.+2.j], > [ 1.+3.j, 1.+4.j, 1.+5.j], > [ 1.+6.j, 1.+7.j, 1.+8.j]]) If you look at a_conj now, you should see that it is the same as a. > >>> Numeric.multiply(a,a_conj) > array([[ 1. +0.j, 0. +2.j, -3. +4.j], > [ -8. +6.j, -15. +8.j, -24.+10.j], > [-35.+12.j, -48.+14.j, -63.+16.j]]) So what you have here is really a squared. So, you could get this to work by replacing slicing with array(a_conf). A much simpler way is: a = Numeric.conjugate(a_conj) a*a_conj #... Hope that clears things up for you. -tim > where the answer should be [[1+0j,2+0j,5+0j][10+0j,... > > ################################# > Aureli Soria Frisch > Fraunhofer IPK > Dept. Pattern Recognition > > post: Pascalstr. 8-9, 10587 Berlin, Germany > e-mail:au...@ip... > fon: +49 30 39 00 61 50 > fax: +49 30 39 17 517 > ################################# > > > > _______________________________________________ > Numpy-discussion mailing list > Num...@li... > http://lists.sourceforge.net/lists/listinfo/numpy-discussion |