<h3 dir="auto">Reproducing code example:</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy
numpy.unique(numpy.empty((0, 2)), axis=0)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span>
<span class="pl-s1">numpy</span>.<span class="pl-en">unique</span>(<span class="pl-s1">numpy</span>.<span class="pl-en">empty</span>((<span class="pl-c1">0</span>, <span class="pl-c1">2</span>)), <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)</pre></div>
<h3 dir="auto">Error message:</h3>
<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;&lt;__array_function__ internals&gt;&quot;, line 5, in unique
  File &quot;/opt/python/3.8.2.1/lib/python3.8/site-packages/numpy/lib/arraysetops.py&quot;, line 275, in unique
    ar = ar.reshape(orig_shape[0], -1)
ValueError: cannot reshape array of size 0 into shape (0,newaxis)"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;__array_function__ internals&gt;", line 5, in unique
  File "/opt/python/3.8.2.1/lib/python3.8/site-packages/numpy/lib/arraysetops.py", line 275, in unique
    ar = ar.reshape(orig_shape[0], -1)
ValueError: cannot reshape array of size 0 into shape (0,newaxis)
</code></pre></div>
<h3 dir="auto">NumPy/Python version information:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="1.18.2 3.8.2 (default, May 13 2020, 11:50:46)
[GCC 8.1.0 20180502 (Cray Inc.)]"><pre class="notranslate"><code class="notranslate">1.18.2 3.8.2 (default, May 13 2020, 11:50:46)
[GCC 8.1.0 20180502 (Cray Inc.)]
</code></pre></div>
<p dir="auto">Using <code class="notranslate">np.unique</code> with the <code class="notranslate">axis</code> argument on a multidimensional array with zero in one or more of the dimensions hits <code class="notranslate">ValueError</code> failures, seemingly due to sizes/reshaping.</p>
<p dir="auto">When <code class="notranslate">axis</code> is one of the zero dimensions (that is, <code class="notranslate">shape[axis] == 0</code>), it throws <code class="notranslate">ValueError: cannot reshape array of size 0 into shape (0,newaxis)</code>.</p>
<p dir="auto">When <code class="notranslate">axis</code> is a non-zero dimension (<code class="notranslate">shape[axis] == 1</code>), it throws <code class="notranslate">ValueError: When changing to a smaller dtype, its size must be a divisor of the size of original dtype</code>.</p>
<h3 dir="auto">Reproducing code example:</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
arr = np.zeros(shape=(0, 10))

np.unique(arr, axis=0)
# ValueError: cannot reshape array of size 0 into shape (0,newaxis)

np.unique(arr, axis=1)
# ValueError: When changing to a smaller dtype, its size must be a divisor of the size of original dtype

# equivalent code with non-zero dimension works as expected:
arr = np.zeros(shape=(1, 10))
np.unique(arr, axis=0)
# array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])
np.unique(arr, axis=1)
# array([[0.]])"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">zeros</span>(<span class="pl-s1">shape</span><span class="pl-c1">=</span>(<span class="pl-c1">0</span>, <span class="pl-c1">10</span>))

<span class="pl-s1">np</span>.<span class="pl-en">unique</span>(<span class="pl-s1">arr</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
<span class="pl-c"># ValueError: cannot reshape array of size 0 into shape (0,newaxis)</span>

<span class="pl-s1">np</span>.<span class="pl-en">unique</span>(<span class="pl-s1">arr</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)
<span class="pl-c"># ValueError: When changing to a smaller dtype, its size must be a divisor of the size of original dtype</span>

<span class="pl-c"># equivalent code with non-zero dimension works as expected:</span>
<span class="pl-s1">arr</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">zeros</span>(<span class="pl-s1">shape</span><span class="pl-c1">=</span>(<span class="pl-c1">1</span>, <span class="pl-c1">10</span>))
<span class="pl-s1">np</span>.<span class="pl-en">unique</span>(<span class="pl-s1">arr</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
<span class="pl-c"># array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])</span>
<span class="pl-s1">np</span>.<span class="pl-en">unique</span>(<span class="pl-s1">arr</span>, <span class="pl-s1">axis</span><span class="pl-c1">=</span><span class="pl-c1">1</span>)
<span class="pl-c"># array([[0.]])</span></pre></div>
<h3 dir="auto">Error message:</h3>
<p dir="auto"><code class="notranslate">np.unique(arr, axis=0)</code></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;&lt;__array_function__ internals&gt;&quot;, line 6, in unique
  File &quot;~/.pyenv/versions/numpy-bug/lib/python3.6/site-packages/numpy/lib/arraysetops.py&quot;, line 275, in unique
    ar = ar.reshape(orig_shape[0], -1)
ValueError: cannot reshape array of size 0 into shape (0,newaxis)"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;__array_function__ internals&gt;", line 6, in unique
  File "~/.pyenv/versions/numpy-bug/lib/python3.6/site-packages/numpy/lib/arraysetops.py", line 275, in unique
    ar = ar.reshape(orig_shape[0], -1)
ValueError: cannot reshape array of size 0 into shape (0,newaxis)
</code></pre></div>
<p dir="auto"><code class="notranslate">np.unique(arr, axis=1)</code></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;&lt;__array_function__ internals&gt;&quot;, line 6, in unique
  File &quot;~/.pyenv/versions/numpy-bug/lib/python3.6/site-packages/numpy/lib/arraysetops.py&quot;, line 280, in unique
    consolidated = ar.view(dtype)
ValueError: When changing to a smaller dtype, its size must be a divisor of the size of original dtype"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "&lt;__array_function__ internals&gt;", line 6, in unique
  File "~/.pyenv/versions/numpy-bug/lib/python3.6/site-packages/numpy/lib/arraysetops.py", line 280, in unique
    consolidated = ar.view(dtype)
ValueError: When changing to a smaller dtype, its size must be a divisor of the size of original dtype
</code></pre></div>
<h3 dir="auto">Numpy/Python version information:</h3>
<p dir="auto">Numpy: <code class="notranslate">1.18.1</code><br>
Python: <code class="notranslate">3.6.9 (default, Jul 10 2019, 12:25:55) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)]</code></p>