title: Running same python code multiple times and getting inconsistent results
body: <p>I am new to Python, so I am not sure if this problem is due to my inexperience or whether this is a glitch.</p>
  <p>I am running this code multiple times on the same data (no random number generation) and getting different results. This has occurred with more than one variable so far, and obviously I cannot proceed with the analysis until I figure out which results are trustworthy. Here is a short sample of the results I have obtained after running the code four times. Why is there such a discrepancy between these outputs? I am puzzled and greatly appreciate your advice.</p>
  <h1>Linear Regression</h1>
  <pre><code>    from scipy.stats import linregress
      import scipy.stats
      from scipy.signal import welch
      import matplotlib
      import pandas as pd
      import matplotlib.pyplot as plt
      import numpy as np
      import scipy.signal as signal
  
  part_022_o = pd.read_excel(r'C:\Users\Me\Desktop\Behavioral Data Processed\part_022_combined_other.xlsx')
          
  distance_o = part_022_o[&quot;distance&quot;]
          
  fs = 200
          
  f, Pwelch_spec = signal.welch(distance_o, fs=fs, window='hanning',nperseg=400, noverlap=200, scaling='density', average='mean')
          
  log_f = np.log(f, where=f&gt;0)
  log_pwelch = np.log(Pwelch_spec, where=Pwelch_spec&gt;0)
  idx = np.isfinite(log_f) &amp; np.isfinite(log_pwelch)          
  polynomial_coefficients = np.polyfit(log_f[idx],log_pwelch[idx],1)
      print(polynomial_coefficients)
  
  scipy.stats.linregress(log_f[idx], log_pwelch[idx])
  </code></pre>
  <h1>Results First Attempt</h1>
  <p>[ 0.00324568 -2.82962602]</p>
  <h1>Results Second Attempt</h1>
  <p>[-2.70137164  6.97117509]</p>
  <h1>Results Third Attempt</h1>
  <p>[-2.70137164  6.97117509]</p>
  <h1>Results Fourth Attempt</h1>
  <p>[-2.28028005  5.53839502]</p>
  <p>The same thing happens when I use scipy.stats.linregress().</p>
  <p>Thank you,</p>
  <p>Confused</p>
  <p>Edit: full code added.
  Also, the issue appears to be related to np.log(), since only the values of &quot;log_f&quot; array seem to be changing with the different outputs. It is hard to be certain that nothing else is changing (e.g. log_pwelch), but differences in output clearly correspond to differences in the first value of the &quot;log_f&quot; array.</p>
  <p>Edit: I have narrowed the issue down to np.log(f, where=f&gt;0). The first value in the f array is zero. According to the documentation of numpy log, &quot;...Note that if an uninitialized out array is created via the default out=None, <em>locations within it where the condition is False will remain uninitialized</em>.&quot; Apparently this means that the value or variable is unpredictable and can vary from trial to trial, which is exactly what I am observing. Given my inexperience with Python, I am not sure what the best solution is (e.g. specifying the out-array in the log function, use a random seed, just note the regression coefficients whenever the value of zero is unchanged after log, etc.)</p>