<p dir="auto"><code class="notranslate">np.random.choice</code> requires the upper limit <code class="notranslate">a &gt; 0</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; np.random.choice(0, size=0)
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;mtrand.pyx&quot;, line 1120, in mtrand.RandomState.choice
ValueError: a must be greater than 0"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; np.random.choice(0, size=0)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "mtrand.pyx", line 1120, in mtrand.RandomState.choice
ValueError: a must be greater than 0
</code></pre></div>
<p dir="auto">This is necessary if <code class="notranslate">size &gt; 0</code>, but if <code class="notranslate">size == 0</code> we could permit this special case.  Allowing the valid special case would simplify certain code, and in particular would make <code class="notranslate">np.random.choice(limit, size=min(n, limit)</code> always work.  The same goes for <code class="notranslate">np.random.randint</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; np.random.randint(0, size=0)
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;mtrand.pyx&quot;, line 993, in mtrand.RandomState.randint
ValueError: low &gt;= high"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; np.random.randint(0, size=0)
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "mtrand.pyx", line 993, in mtrand.RandomState.randint
ValueError: low &gt;= high
</code></pre></div>
<p dir="auto">This piece of code:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="np.random.choice([],size=0)"><pre class="notranslate"><span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">choice</span>([],<span class="pl-s1">size</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)</pre></div>
<p dir="auto">Generates this error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;mtrand.pyx&quot;, line 1397, in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:15499)
ValueError: a must be non-empty"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "mtrand.pyx", line 1397, in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:15499)
ValueError: a must be non-empty
</code></pre></div>
<p dir="auto">This error makes sense when <code class="notranslate">size&gt;0</code>, but when <code class="notranslate">size=0</code>, <code class="notranslate">random.choice</code> could simply return <code class="notranslate">[]</code>. This would be useful when the <code class="notranslate">a</code> and <code class="notranslate">size</code> parameters are variable. Right now this situation requires an additional check:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="if size &gt; 0:
  result = np.random.choice(a,size)
else:
  result = np.array([])"><pre class="notranslate"><span class="pl-k">if</span> <span class="pl-s1">size</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">0</span>:
  <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">choice</span>(<span class="pl-s1">a</span>,<span class="pl-s1">size</span>)
<span class="pl-k">else</span>:
  <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([])</pre></div>
<p dir="auto">Would it be a good idea to simply return an empty array when <code class="notranslate">size=0</code>? This is my first issue so I hope this is the right way to address this.</p>
<p dir="auto">I created a simple patch that implements this: 57ab0728d4cf73c1f4b3af2450fe603bf8670b75</p>
<p dir="auto">I'm using Python 3.5.2 with numpy 1.11.2.</p>
<p dir="auto">Edit: My implementation returns an empty slice from the original array. My thinking was that this would assign the correct <code class="notranslate">base</code> to the resulting array, but on second thought this is not what happens with <code class="notranslate">random.choice</code> normally, so I think returning <code class="notranslate">np.array([])</code> would be better.</p>