<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [2]: np.arange(20, dtype='uint') &lt;&lt; 64
Out[2]: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=uint64)

In [3]: np.arange(10, dtype='uint') &lt;&lt; 64
Out[3]: array([0, 0, 0, 0, 0, 0, 0, 0, 8, 9], dtype=uint64)

In [4]: np.arange(5, dtype='uint') &lt;&lt; 64
Out[4]: array([0, 1, 2, 3, 4], dtype=uint64)"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">2</span>]: <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">20</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'uint'</span>) <span class="pl-c1">&lt;&lt;</span> <span class="pl-c1">64</span>
<span class="pl-v">Out</span>[<span class="pl-c1">2</span>]: <span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">uint64</span>)

<span class="pl-v">In</span> [<span class="pl-c1">3</span>]: <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">10</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'uint'</span>) <span class="pl-c1">&lt;&lt;</span> <span class="pl-c1">64</span>
<span class="pl-v">Out</span>[<span class="pl-c1">3</span>]: <span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">8</span>, <span class="pl-c1">9</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">uint64</span>)

<span class="pl-v">In</span> [<span class="pl-c1">4</span>]: <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">5</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'uint'</span>) <span class="pl-c1">&lt;&lt;</span> <span class="pl-c1">64</span>
<span class="pl-v">Out</span>[<span class="pl-c1">4</span>]: <span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">uint64</span>)</pre></div>
<p dir="auto">My understanding is that while <code class="notranslate">numpy.left_shift</code> should execute a rotation (despite the docs not mentioning this word), the <code class="notranslate">&lt;&lt;</code> operator should execute a shift (that is, drop overflowing bits). At least, things seem to work this way with values below 64:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [5]: (np.arange(20, dtype='uint') &lt;&lt; 63 == (np.arange(20, dtype='uint') % 2 * 2) ** 63).all()
Out[5]: True

In [6]: (np.arange(10, dtype='uint') &lt;&lt; 63 == (np.arange(10, dtype='uint') % 2 * 2) ** 63).all()
Out[6]: True

In [7]: (np.arange(5, dtype='uint') &lt;&lt; 63 == (np.arange(5, dtype='uint') % 2 * 2) ** 63).all()
Out[7]: True"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">5</span>]: (<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">20</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'uint'</span>) <span class="pl-c1">&lt;&lt;</span> <span class="pl-c1">63</span> <span class="pl-c1">==</span> (<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">20</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'uint'</span>) <span class="pl-c1">%</span> <span class="pl-c1">2</span> <span class="pl-c1">*</span> <span class="pl-c1">2</span>) <span class="pl-c1">**</span> <span class="pl-c1">63</span>).<span class="pl-en">all</span>()
<span class="pl-v">Out</span>[<span class="pl-c1">5</span>]: <span class="pl-c1">True</span>

<span class="pl-v">In</span> [<span class="pl-c1">6</span>]: (<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">10</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'uint'</span>) <span class="pl-c1">&lt;&lt;</span> <span class="pl-c1">63</span> <span class="pl-c1">==</span> (<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">10</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'uint'</span>) <span class="pl-c1">%</span> <span class="pl-c1">2</span> <span class="pl-c1">*</span> <span class="pl-c1">2</span>) <span class="pl-c1">**</span> <span class="pl-c1">63</span>).<span class="pl-en">all</span>()
<span class="pl-v">Out</span>[<span class="pl-c1">6</span>]: <span class="pl-c1">True</span>

<span class="pl-v">In</span> [<span class="pl-c1">7</span>]: (<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">5</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'uint'</span>) <span class="pl-c1">&lt;&lt;</span> <span class="pl-c1">63</span> <span class="pl-c1">==</span> (<span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">5</span>, <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s">'uint'</span>) <span class="pl-c1">%</span> <span class="pl-c1">2</span> <span class="pl-c1">*</span> <span class="pl-c1">2</span>) <span class="pl-c1">**</span> <span class="pl-c1">63</span>).<span class="pl-en">all</span>()
<span class="pl-v">Out</span>[<span class="pl-c1">7</span>]: <span class="pl-c1">True</span></pre></div>
<p dir="auto">Instead with 64 some cases (<code class="notranslate">In [2]:</code>) shift, some (<code class="notranslate">In [4]:</code>) rotate, and some (<code class="notranslate">In [3]:</code>) mix the two behaviors!</p>
<p dir="auto">I'm using <code class="notranslate">uint</code> for simplicity, but the behavior is not limited to unsigned ints:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="In [8]: np.arange(20) &lt;&lt; 64
Out[8]: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

In [9]: np.arange(5) &lt;&lt; 64
Out[9]: array([0, 1, 2, 3, 4])"><pre class="notranslate"><span class="pl-v">In</span> [<span class="pl-c1">8</span>]: <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">20</span>) <span class="pl-c1">&lt;&lt;</span> <span class="pl-c1">64</span>
<span class="pl-v">Out</span>[<span class="pl-c1">8</span>]: <span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>])

<span class="pl-v">In</span> [<span class="pl-c1">9</span>]: <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">5</span>) <span class="pl-c1">&lt;&lt;</span> <span class="pl-c1">64</span>
<span class="pl-v">Out</span>[<span class="pl-c1">9</span>]: <span class="pl-en">array</span>([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">2</span>, <span class="pl-c1">3</span>, <span class="pl-c1">4</span>])</pre></div>
<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1856" rel="nofollow">http://projects.scipy.org/numpy/ticket/1856</a> on 2011-06-02 by trac user klasj, assigned to unknown.</em></p>
<p dir="auto">The bitshift operations, both right and left cycles when they are shifted more bits than<br>
the length of the datatype. This happens for both int32 and int64 but not for int16,<br>
unsigned integers works as expected. In the example below version 1.6.1 is used but<br>
this is also present in at least 1.5.0.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [1]: import numpy as np

In [2]: np.right_shift(np.int32(8),32)

Out[2]: 8

In [3]: np.right_shift(np.int64(8),64)

Out[3]: 8

In [4]: np.right_shift(np.int16(8),16)

Out[4]: 0

In [5]: np.left_shift(np.int32(8),32)

Out[5]: 8

In [6]: np.left_shift(np.int64(8),64)

Out[6]: 8

In [7]: np.left_shift(np.int16(8),16)

Out[7]: 524288

In [8]: np.version.full_version

Out[8]: '1.6.1.dev-08953ea'"><pre class="notranslate"><code class="notranslate">In [1]: import numpy as np

In [2]: np.right_shift(np.int32(8),32)

Out[2]: 8

In [3]: np.right_shift(np.int64(8),64)

Out[3]: 8

In [4]: np.right_shift(np.int16(8),16)

Out[4]: 0

In [5]: np.left_shift(np.int32(8),32)

Out[5]: 8

In [6]: np.left_shift(np.int64(8),64)

Out[6]: 8

In [7]: np.left_shift(np.int16(8),16)

Out[7]: 524288

In [8]: np.version.full_version

Out[8]: '1.6.1.dev-08953ea'
</code></pre></div>