title: Generating random numbers for testing a kernel density estimate
body: <p>I have a one dimensional dataset from which I have calculated the kernel density estimate, using statsmodels and also with scipy, in python.</p>
  
  <p>I want to generate a set of random numbers to see if they give me the same distribution or not.</p>
  
  <p>The solution I could find so far was this :</p>
  
  <blockquote>
    <p>To draw a number x between 0 and 1 and return cdf^{-1}(x), where
    cdf^{-1} is the inverse cumulative distribution function of 'f'.</p>
  </blockquote>
  
  <p>Problem with this is, using statsmodel I am able to find the inverse cumulative distribution, but in the form of a matrix. So multiplying a number x with the matrix is not giving me a random sample from the distribution of the calculated KDE.</p>
  
  <p>How can I generate a random number from the given KDE function or distribution?</p>
  
  <p>EDIT:
  Here is a code sample:</p>
  
  <pre><code>def calcKDE(data):
      #Calculating KDE
      kde = sm.nonparametric.KDEUnivariate(data)
      kde.fit(kernel='gau', bw='silverman')
      return kde
  def generateData(data, kde):
      inverse_cdf = kde.icdf // this is a method which takes no parameters, and so is kde.cdf
      randomSet = np.random.random(1) * inverse_cdf // inverse_cdf is taken as a matrix, will also add a loop here to return 1000 random values
      return randomSet
  </code></pre>