<p dir="auto">If one tries to use the string index syntax of the r_ object, and it crashes due to an error, it seems like it retains it internal state, making it behave inconsistently.<br>
It can be made consistent again by simply resetting the internal state.</p>
<p dir="auto">my version of numpy is <code class="notranslate">1.11.1</code>.<br>
python is the version 3.4.3+<br>
running on Linux Kubuntu 15.10<br>
Kernel: 4.2.0-42-generic  x86_64</p>
<p dir="auto">the error can be replicated with this code</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# this works fine
r_[1, 2]
print(r_.axis) # 0

# this works fine, and the state is maintained
r_['1', [[1, 2]]]
print(r_.axis) # 0

# this crashes, and the state is modified
try:
    r_['1', [1, 2]]
except IndexError as e:
    print(e) # axis 1 out of bounds [0, 1)
finally:
    print(r_.axis) # 1

# now this previously correct code crashes as well
try:
    r_[1, 2]
except IndexError as e:
    print(e) # axis 1 out of bounds [0, 1)

# by resetting the wrong value it works again
r_.axis = 0
r_[1, 2]"><pre class="notranslate"><code class="notranslate"># this works fine
r_[1, 2]
print(r_.axis) # 0

# this works fine, and the state is maintained
r_['1', [[1, 2]]]
print(r_.axis) # 0

# this crashes, and the state is modified
try:
    r_['1', [1, 2]]
except IndexError as e:
    print(e) # axis 1 out of bounds [0, 1)
finally:
    print(r_.axis) # 1

# now this previously correct code crashes as well
try:
    r_[1, 2]
except IndexError as e:
    print(e) # axis 1 out of bounds [0, 1)

# by resetting the wrong value it works again
r_.axis = 0
r_[1, 2]
</code></pre></div>
<p dir="auto">Consider the following code:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from __future__ import print_function

import numpy as np

a = np.ones((3, 3, 3))
b = np.zeros((3, 3))

# Uncommenting this will make the below call to `np.r_` work.
# try:
# 	np.r_['2,3', a, b]
# except ValueError:
# 	print('failure')

print(np.r_[a, b.reshape((3, 3, 1))])"><pre class="notranslate"><span class="pl-k">from</span> __future__ <span class="pl-k">import</span> <span class="pl-s1">print_function</span>

<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">a</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ones</span>((<span class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span class="pl-c1">3</span>))
<span class="pl-s1">b</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">zeros</span>((<span class="pl-c1">3</span>, <span class="pl-c1">3</span>))

<span class="pl-c"># Uncommenting this will make the below call to `np.r_` work.</span>
<span class="pl-c"># try:</span>
<span class="pl-c"># 	np.r_['2,3', a, b]</span>
<span class="pl-c"># except ValueError:</span>
<span class="pl-c"># 	print('failure')</span>

<span class="pl-en">print</span>(<span class="pl-s1">np</span>.<span class="pl-s1">r_</span>[<span class="pl-s1">a</span>, <span class="pl-s1">b</span>.<span class="pl-en">reshape</span>((<span class="pl-c1">3</span>, <span class="pl-c1">3</span>, <span class="pl-c1">1</span>))])</pre></div>
<p dir="auto">This fails with:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    Traceback (most recent call last):
  File &quot;test.py&quot;, line 13, in &lt;module&gt;
    print(numpy.r_[a, b.reshape((3, 3, 1))])
  File &quot;/usr/local/lib/python2.7/dist-packages/numpy/lib/index_tricks.py&quot;, line 338, in __getitem__
    res = _nx.concatenate(tuple(objs), axis=self.axis)
ValueError: all the input array dimensions except for the concatenation axis must match exactly"><pre class="notranslate"><code class="notranslate">    Traceback (most recent call last):
  File "test.py", line 13, in &lt;module&gt;
    print(numpy.r_[a, b.reshape((3, 3, 1))])
  File "/usr/local/lib/python2.7/dist-packages/numpy/lib/index_tricks.py", line 338, in __getitem__
    res = _nx.concatenate(tuple(objs), axis=self.axis)
ValueError: all the input array dimensions except for the concatenation axis must match exactly
</code></pre></div>
<p dir="auto">All right as the dimensions don't match indeed. However uncommenting the above <code class="notranslate">try/except</code> block will make the second call to <code class="notranslate">numpy.r_</code> work, just as it was <code class="notranslate">numpy.r_['2,3', a, b.reshape((3, 3, 1))]</code> instead (stacking along the last axis). So it seems that <code class="notranslate">numpy.r_</code> still has that string from the previous failing call cached and is using it for the second call.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="failure
[[[ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]]

 [[ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]]

 [[ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]]]"><pre class="notranslate"><code class="notranslate">failure
[[[ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]]

 [[ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]]

 [[ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]]]
</code></pre></div>
<p dir="auto">Tested on:</p>
<ul dir="auto">
<li>Python 2.7.12 + numpy==1.12.0</li>
<li>Python 3.5.2 + numpy==1.12.0</li>
</ul>