<p style="margin-bottom:0cm">Hello, 
</p>
<p style="margin-bottom:0cm">This is a continuation of a problem I
had last year,</p>
<p style="margin-bottom:0cm"><a href="http://old.nabble.com/Apparently-non-deterministic-behaviour-of-complex-array-multiplication-tt32893004.html#a32931369" target="_blank">http://old.nabble.com/Apparently-non-deterministic-behaviour-of-complex-array-multiplication-tt32893004.html#a32931369</a></p>



<p style="margin-bottom:0cm"> at least it seems to have similar
symptoms.  I am working again with complex valued arrays in numpy
(python version 2.7.3).  This time however, the dataset is not very
large, and I am able to post a snippet of the code.  
</p>
<p style="margin-bottom:0cm">I became aware of the problem working
in and IDE: Spyder 2.1.9, where I was repeatedly running code by
pushing f5 and checking that my numerical results were what I expect.
 What I found was that the output in spyder varied somewhat randomly.
 In particular, when initializing a 2x2 complex-valued numpy array on
line 32 of the code called “lowTri”.
</p><p style="margin-bottom:0cm">When I print the value of the upper
right element (the one that should be zero) I often see 1.789+1.543j, or 0+1.543j, or 0+0j.  This behavior happens when I run the
code using f5 in spyder, and I thought it may be a Spyder issue, but
further investigation has shown equally strange behavior on the
command line as well.
</p><p style="margin-bottom:0cm">When I run this script on the command
line the output is usually the same from run to run (although I have
seen some variations, which I do not understand), but most
remarkable, and reproducible, is that if I comment out line 17 (where
the complex-valued array zzz is populated), the behavior of the
initialization of lowTri varies.  <br></p><p style="margin-bottom:0cm">With Line 17 uncommented I usually get
(on the command line):
</p><p style="margin-bottom:0cm">Lower Triangular [0,1]: 1.543j

</p><p style="margin-bottom:0cm">[[ 670.9 +1.22400000e-05j    0.0
+1.54300000e+00j]
</p>
<p style="margin-bottom:0cm"> [ 195.8 -1.17300000e+02j  391.2
+1.46900000e-05j]]
</p>
<p style="margin-bottom:0cm">Lower Triangular [0,1]: 1.543j
</p>
<p style="margin-bottom:0cm">Real Part 0.0
</p>
<p style="margin-bottom:0cm"><br>
</p>and with line 17 it commented: 

<p style="margin-bottom:0cm">Lower Triangular [0,1]: 0j
</p>
<p style="margin-bottom:0cm">[[ 670.9 +1.22400000e-05j    0.0
+0.00000000e+00j]
</p>
<p style="margin-bottom:0cm"> [ 195.8 -1.17300000e+02j  391.2
+1.46900000e-05j]]
</p>
<p style="margin-bottom:0cm">Lower Triangular [0,1]: 0j
</p>
<p style="margin-bottom:0cm">Real Part 0.0
</p>
<p style="margin-bottom:0cm">I.e.. the imaginary part is initialized
to a different value.  From reading up on forums I think I understand
that when an array is allocated without specific values, it will be
given random values which are very small, ie. ~1e-316 or so.  But it
would seem that sometimes initallization is done to a finite
quantity.  I know I can try to initialize the array using np.zeros()
instead of np.ndarray(), but it is the principle <span style="font-style:normal">I
am concerned about.  </span>

</p><p style="margin-bottom:0cm"><span style="font-style:normal">Last
year it had been suggested that I had bad RAM, but these issues are
reproducing on four computers, one of which has a new motherboard/RAM
and AMD processor, and the others are Intel.  Memtest has been run
recently on at least two of the machines.</span>
</p><p style="margin-bottom:0cm"><span style="font-style:normal">Could
someone try running this script with and without line 17 commented
out and tell me if they are getting the same sort of behaviour?</span>
</p><p style="margin-bottom:0cm"><span style="font-style:normal">Thanks, <br></span></p><p style="margin-bottom:0cm"><span style="font-style:normal">Karl</span></p><p style="margin-bottom:0cm"><br><span style="font-style:normal"></span></p>


<p style="margin-bottom:0cm"><span style="font-style:normal">**********************************</span></p><p style="margin-bottom:0cm"><br>

</p><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">import numpy as np</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">if __name__ == "__main__":</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    a={}</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    a[0] = '0.1537E+00  0.1610E+01 -0.4801E+01 -0.3175E+01'</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    a[1] = '0.1789E+01  0.1543E+01 -0.5524E+00 -0.8423E+00'</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    c = '0.6709E+03  0.1224E-04 0.1958E+03 -0.1173E+03  0.3912E+03  0.1469E-04'</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    ztmp = np.zeros((4,2))</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    zzz = np.zeros((2,2)) + complex(0,1)*np.zeros((2,2));</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    line = []</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    for iE in range(2):</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        line = a[iE].split()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        for iElt, elt in enumerate(line):</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">            ztmp[iElt,iE] = float(elt)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    zzz[:,0:2] = ztmp[[0,2],:] + complex(0,1)*ztmp[[1,3],:] #commenting this line seems to affect value of lowTri</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    stemp = np.zeros((2,3))</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    nElts =  np.prod(stemp.shape)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    v = []</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    line = c.split()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    for l in line:</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        v.append(float(l))</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    N=len(v)/2</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    cVec = np.ndarray(shape=(N), dtype=complex)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    for i in range(N):</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        cVec[i] = complex(float(v[2*i]),float(v[2*(i+1)-1]))</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    lowTri = np.ndarray(shape=(2,2), dtype=complex)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    #lowTri = np.zeros(shape=(2,2), dtype=complex)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    print("Lower Triangular [0,1]: {}".format(lowTri[0,1]))</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    TI = np.tril_indices(2)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    rows = TI[0]</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    cols = TI[1]</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    for iCell in range(len(rows)):</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">        lowTri[rows[iCell],cols[iCell]] = cVec[iCell]</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    print lowTri</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    print("Lower Triangular [0,1]: {}".format(lowTri[0,1]))</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">    print("Real Part {}".format(np.real(lowTri[0,1])))</p><p style="margin-bottom:0cm">
</p>