Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong> Created functions that return the full set of numbers, not just one row at a time. <strong>EDIT 2</strong> Make the functions more pythonic (and faster), add solution for second question</p> <p>For the first set of numbers, you might consider <code>numpy.random.randint</code> or <code>numpy.random.uniform</code>, which take <code>low</code> and <code>high</code> parameters. Generating an array of 7 x 1,000,000 numbers in a specified range seems to take &lt; 0.7 second on my 2 GHz machine:</p> <pre><code>def LimitedRandInts(XLim, N): rowlen = (1,N) return [np.random.randint(low=0,high=lim,size=rowlen) for lim in XLim] def LimitedRandDoubles(XLim, N): rowlen = (1,N) return [np.random.uniform(low=0,high=lim,size=rowlen) for lim in XLim] &gt;&gt;&gt; import numpy as np &gt;&gt;&gt; N = 1000000 #number of randoms in each range &gt;&gt;&gt; xLim = [x*500 for x in range(1,8)] #convenient limit generation &gt;&gt;&gt; fLim = [x/7.0 for x in range(1,8)] &gt;&gt;&gt; aa = LimitedRandInts(xLim, N) &gt;&gt;&gt; ff = LimitedRandDoubles(fLim, N) </code></pre> <p>This returns integers in [0,xLim-1] or floats in [0,fLim). The integer version took ~0.3 seconds, the double ~0.66, on my 2 GHz single-core machine.</p> <p>For the second set, I used @Joe Kingston's suggestion.</p> <pre><code>def SumToOneRands(NumToSum, N): aa = np.random.uniform(low=0,high=1.0,size=(NumToSum,N)) #13 rows by 1000000 columns, for instance s = np.reciprocal(aa.sum(0)) aa *= s return aa.T #get back to column major order, so aa[k] is the kth set of 13 numbers &gt;&gt;&gt; ll = SumToOneRands(13, N) </code></pre> <p>This takes ~1.6 seconds.</p> <p>In all cases, <code>result[k]</code> gives you the kth set of data.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload