[SciPy-User] problem with dot for complex matrices

Ryan Krauss ryanlists at gmail.com
Tue Mar 27 15:26:02 EDT 2012


To further add to my own mystery, why does this fix the problem:

In [37]: -1*numpy.dot(submat_inv_num, augcol_num)
Out[37]:
array([[  5.30985737e-05+0.00038316j],
       [  1.72370377e-04+0.00115503j]])

In [38]: A2 = copy.copy(submat_inv_num)

In [39]: B2 = copy.copy(augcol_num)

In [40]: -1*dot(A2,B2)
Out[40]:
array([[-0.00532766+0.00112881j],
       [-0.01604775+0.00343208j]])


On Tue, Mar 27, 2012 at 2:15 PM, eat <e.antero.tammi at gmail.com> wrote:
> Hi,
>
> On Tue, Mar 27, 2012 at 9:48 PM, Ryan Krauss <ryanlists at gmail.com> wrote:
>>
>> I am loosing my mind while trying to debug some code.  I am trying to
>> find the cause of some differences between numpy analysis and analysis
>> done first in maxima and then converted to python code.  The maxima
>> approach is more difficult to do, but seems to lead to the correct
>> answers.  The core issue seems to be one dot product of a 2x2 and a
>> 2x1 that are both complex numbers:
>>
>> here is the 2x2:
>>
>> ipdb> submatinv
>> array([[-0.22740265-1.63857451j, -0.07740957-0.55847886j],
>>       [-3.20602957-4.93959054j, -0.36746252-1.68352465j]])
>>
>> here is the 2x1:
>>
>> ipdb> augcol
>> array([[ -3.74729148e-05-0.0005937j ],
>>       [  7.96025801e-04+0.01137658j]])
>>
>> verifying their shapes and data types:
>>
>> ipdb> submatinv.shape
>> (2, 2)
>> ipdb> submatinv.dtype
>> dtype('complex128')
>> ipdb> augcol.shape
>> (2, 1)
>> ipdb> augcol.dtype
>> dtype('complex128')
>>
>> I need to compute this result:
>>
>> ipdb> -1*numpy.dot(submatinv,augcol)
>> array([[  5.30985737e-05+0.00038316j],
>>       [  1.72370377e-04+0.00115503j]])
>>
>> If I hard code how to do the matrix multiplication, I get the correct
>> answer (it agrees with Maxima):
>>
>> For the first element:
>> ipdb> -1*(submatinv[0,0]*augcol[0,0]+submatinv[0,1]*augcol[1,0])
>> (-0.005327660633034575+0.0011288088216130766j)
>>
>> For the second
>> ipdb> -1*(submatinv[1,0]*augcol[0,0]+submatinv[1,1]*augcol[1,0])
>> (-0.016047752110848554+0.003432076134378004j)
>>
>> What is the dot product doing if it isn't dotting row by column?
>>
>> I am not seeing something.
>
> FWIIWO, I can't either reproduce your results:
> In []: sys.version
> Out[]: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]'
> In []: np.version.version
> Out[]: '1.6.0'
>
> In []: s.round(7)
> Out[]:
> array([[-0.2274026-1.6385745j, -0.0774096-0.5584789j],
>        [-3.2060296-4.9395905j, -0.3674625-1.6835246j]])
> In []: a.round(7)
> Out[]:
> array([[ -3.75000000e-05-0.0005937j],
>        [  7.96000000e-04+0.0113766j]])
>
> In []: -1* dot(s, a).round(7)
> Out[]:
> array([[-0.0053277+0.0011288j],
>        [-0.0160477+0.0034321j]])
>
> Regards,
> -eat
>>
>>
>> Thanks,
>>
>> Ryan
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list