<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/1705" rel="nofollow">http://projects.scipy.org/scipy/ticket/1705</a> on 2012-07-20 by trac user ale.fener, assigned to unknown.</em></p>
<p dir="auto">Hi all.<br>
I was using the class gaussian_kde with a similar code snippet:</p>
<p dir="auto">density = gaussian_kde(data)<br>
xs = numpy.linspace(xmin, xmax, 2*len(data))<br>
ys = density(xs)</p>
<p dir="auto">the problem is that when data is an array of integers (dunno if it was a numpy array of ints or a python array of ints) then the array ys contains only zeros. There must be a division by an integer somewhere. Converting data to an array of floats solves the problem, but it took me quite some time to understand what was going on.</p>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/scipy/ticket/1181" rel="nofollow">http://projects.scipy.org/scipy/ticket/1181</a> on 2010-05-28 by trac user jakebiesinger, assigned to unknown.</em></p>
<p dir="auto">Creating a gaussian_kde with integer data causes the evaluate function to return all 0's.</p>
<p dir="auto"><strong>Some info</strong>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ python --version
Python 2.6.5
$ ipython --Version
0.10
In [13]: scipy.__version__
Out[13]: '0.7.2'"><pre class="notranslate"><code class="notranslate">$ python --version
Python 2.6.5
$ ipython --Version
0.10
In [13]: scipy.__version__
Out[13]: '0.7.2'
</code></pre></div>
<p dir="auto"><strong>Repro</strong>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ipython
In [1]: from scipy.stats import gaussian_kde
In [2]: import scipy
In [3]: randDistFromCenter = map(int, scipy.rand(10000) * 500 - 250)  # should be uniform on [-250,250)
In [4]: k = gaussian_kde(randDistFromCenter)
/usr/lib/python2.6/dist-packages/scipy/stats/stats.py:1486: DeprecationWarning: scipy.stats.cov is deprecated; please update your code to use numpy.cov.
Please note that:
    - numpy.cov rowvar argument defaults to true, not false
    - numpy.cov bias argument defaults to false, not true

  &quot;&quot;&quot;, DeprecationWarning)
/usr/lib/python2.6/dist-packages/scipy/stats/stats.py:420: DeprecationWarning: scipy.stats.mean is deprecated; please update your code to use numpy.mean.
Please note that:
    - numpy.mean axis argument defaults to None, not 0
    - numpy.mean has a ddof argument to replace bias in a more general manner.
      scipy.stats.mean(a, bias=True) can be replaced by numpy.mean(x,
axis=0, ddof=1).
  axis=0, ddof=1).&quot;&quot;&quot;, DeprecationWarning)

In [5]: x = scipy.linspace(-300,300,100)
In [6]: y = k.evaluate(x)
In [7]: y
Out[7]: 
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0])

# the bandwidth/covariance is calculated correctly
In [8]: k.covariance
Out[8]: array([[ 523.56767608]])"><pre class="notranslate"><code class="notranslate">$ ipython
In [1]: from scipy.stats import gaussian_kde
In [2]: import scipy
In [3]: randDistFromCenter = map(int, scipy.rand(10000) * 500 - 250)  # should be uniform on [-250,250)
In [4]: k = gaussian_kde(randDistFromCenter)
/usr/lib/python2.6/dist-packages/scipy/stats/stats.py:1486: DeprecationWarning: scipy.stats.cov is deprecated; please update your code to use numpy.cov.
Please note that:
    - numpy.cov rowvar argument defaults to true, not false
    - numpy.cov bias argument defaults to false, not true

  """, DeprecationWarning)
/usr/lib/python2.6/dist-packages/scipy/stats/stats.py:420: DeprecationWarning: scipy.stats.mean is deprecated; please update your code to use numpy.mean.
Please note that:
    - numpy.mean axis argument defaults to None, not 0
    - numpy.mean has a ddof argument to replace bias in a more general manner.
      scipy.stats.mean(a, bias=True) can be replaced by numpy.mean(x,
axis=0, ddof=1).
  axis=0, ddof=1).""", DeprecationWarning)

In [5]: x = scipy.linspace(-300,300,100)
In [6]: y = k.evaluate(x)
In [7]: y
Out[7]: 
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0])

# the bandwidth/covariance is calculated correctly
In [8]: k.covariance
Out[8]: array([[ 523.56767608]])
</code></pre></div>
<p dir="auto"><strong>Workaround:</strong> Convert the datatype to floats</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="k = gaussian_kde(scipy.array(randDistFromCenter, float))
y = k.evaluate(x)
[  2.37718449e-05   4.59333855e-05   8.33629081e-05   1.42283310e-04
  2.28733649e-04   3.46958715e-04   4.97636815e-04   6.76566775e-04
  8.74448533e-04   1.07809127e-03   1.27285862e-03   1.44565290e-03
  1.58750741e-03   1.69501260e-03   1.77025571e-03   1.81947393e-03
...."><pre class="notranslate"><code class="notranslate">k = gaussian_kde(scipy.array(randDistFromCenter, float))
y = k.evaluate(x)
[  2.37718449e-05   4.59333855e-05   8.33629081e-05   1.42283310e-04
  2.28733649e-04   3.46958715e-04   4.97636815e-04   6.76566775e-04
  8.74448533e-04   1.07809127e-03   1.27285862e-03   1.44565290e-03
  1.58750741e-03   1.69501260e-03   1.77025571e-03   1.81947393e-03
....
</code></pre></div>