<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

a = np.array([1, 2, 3])
b = np.array([0.5, 0.5, 0.5])

c = a - b
# c = [0.5, 1.5, 2.5]

# problem is here:
n = np.array([0, 0, 0])  # n will be an integer array and will round c numbers automatically
n[0] = c[0]
n[1] = c[1]
n[2] = c[2]

print('n', n)
# will print [0, 1, 2] without any exception
# must print [0.5, 1.5, 2.5] or give some warning etc."><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">a</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">1</span>, <span class="pl-c1">2</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">array</span>([<span class="pl-c1">0.5</span>, <span class="pl-c1">0.5</span>, <span class="pl-c1">0.5</span>])

<span class="pl-s1">c</span> <span class="pl-c1">=</span> <span class="pl-s1">a</span> <span class="pl-c1">-</span> <span class="pl-s1">b</span>
<span class="pl-c"># c = [0.5, 1.5, 2.5]</span>

<span class="pl-c"># problem is here:</span>
<span class="pl-s1">n</span> <span class="pl-c1">=</span> <span class="pl-s1">np</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-c"># n will be an integer array and will round c numbers automatically</span>
<span class="pl-s1">n</span>[<span class="pl-c1">0</span>] <span class="pl-c1">=</span> <span class="pl-s1">c</span>[<span class="pl-c1">0</span>]
<span class="pl-s1">n</span>[<span class="pl-c1">1</span>] <span class="pl-c1">=</span> <span class="pl-s1">c</span>[<span class="pl-c1">1</span>]
<span class="pl-s1">n</span>[<span class="pl-c1">2</span>] <span class="pl-c1">=</span> <span class="pl-s1">c</span>[<span class="pl-c1">2</span>]

<span class="pl-en">print</span>(<span class="pl-s">'n'</span>, <span class="pl-s1">n</span>)
<span class="pl-c"># will print [0, 1, 2] without any exception</span>
<span class="pl-c"># must print [0.5, 1.5, 2.5] or give some warning etc.</span></pre></div>
<h3 dir="auto">Error message:</h3>


<h3 dir="auto">NumPy/Python version information:</h3>
<h3 dir="auto">Reproducing code example:</h3>
<p dir="auto">Create a file called <code class="notranslate">string.py</code> with the following content</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np

if __name__ == &quot;__main__&quot;:
    pass"><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-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">"__main__"</span>:
    <span class="pl-k">pass</span></pre></div>
<p dir="auto">and run it via <code class="notranslate">python3 string.py</code>.</p>
<h3 dir="auto">Error message:</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;/home/user/Desktop/string.py&quot;, line 1, in &lt;module&gt;
    import numpy as np
  File &quot;/usr/local/lib/python3.6/dist-packages/numpy/__init__.py&quot;, line 228, in &lt;module&gt;
    from .testing import Tester
  File &quot;/usr/local/lib/python3.6/dist-packages/numpy/testing/__init__.py&quot;, line 10, in &lt;module&gt;
    from unittest import TestCase
  File &quot;/usr/lib/python3.6/unittest/__init__.py&quot;, line 59, in &lt;module&gt;
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File &quot;/usr/lib/python3.6/unittest/case.py&quot;, line 6, in &lt;module&gt;
    import logging
  File &quot;/usr/lib/python3.6/logging/__init__.py&quot;, line 28, in &lt;module&gt;
    from string import Template
ImportError: cannot import name 'Template'
Error in sys.excepthook:
Traceback (most recent call last):
  File &quot;/usr/lib/python3/dist-packages/apport_python_hook.py&quot;, line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File &quot;/usr/lib/python3/dist-packages/apport/__init__.py&quot;, line 5, in &lt;module&gt;
    from apport.report import Report
  File &quot;/usr/lib/python3/dist-packages/apport/report.py&quot;, line 21, in &lt;module&gt;
    from urllib.request import urlopen
  File &quot;/usr/lib/python3.6/urllib/request.py&quot;, line 88, in &lt;module&gt;
    import http.client
  File &quot;/usr/lib/python3.6/http/client.py&quot;, line 71, in &lt;module&gt;
    import email.parser
  File &quot;/usr/lib/python3.6/email/parser.py&quot;, line 12, in &lt;module&gt;
    from email.feedparser import FeedParser, BytesFeedParser
  File &quot;/usr/lib/python3.6/email/feedparser.py&quot;, line 27, in &lt;module&gt;
    from email._policybase import compat32
  File &quot;/usr/lib/python3.6/email/_policybase.py&quot;, line 7, in &lt;module&gt;
    from email import header
  File &quot;/usr/lib/python3.6/email/header.py&quot;, line 16, in &lt;module&gt;
    import email.quoprimime
  File &quot;/usr/lib/python3.6/email/quoprimime.py&quot;, line 44, in &lt;module&gt;
    from string import ascii_letters, digits, hexdigits
ImportError: cannot import name 'ascii_letters'

Original exception was:
Traceback (most recent call last):
  File &quot;/home/user/Desktop/string.py&quot;, line 1, in &lt;module&gt;
    import numpy as np
  File &quot;/usr/local/lib/python3.6/dist-packages/numpy/__init__.py&quot;, line 228, in &lt;module&gt;
    from .testing import Tester
  File &quot;/usr/local/lib/python3.6/dist-packages/numpy/testing/__init__.py&quot;, line 10, in &lt;module&gt;
    from unittest import TestCase
  File &quot;/usr/lib/python3.6/unittest/__init__.py&quot;, line 59, in &lt;module&gt;
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File &quot;/usr/lib/python3.6/unittest/case.py&quot;, line 6, in &lt;module&gt;
    import logging
  File &quot;/usr/lib/python3.6/logging/__init__.py&quot;, line 28, in &lt;module&gt;
    from string import Template
ImportError: cannot import name 'Template'"><pre class="notranslate">Traceback (most recent call last):
  File <span class="pl-s"><span class="pl-pds">"</span>/home/user/Desktop/string.py<span class="pl-pds">"</span></span>, line 1, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    import numpy as np
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/local/lib/python3.6/dist-packages/numpy/__init__.py<span class="pl-pds">"</span></span>, line 228, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from .testing import Tester
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/local/lib/python3.6/dist-packages/numpy/testing/__init__.py<span class="pl-pds">"</span></span>, line 10, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from unittest import TestCase
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/unittest/__init__.py<span class="pl-pds">"</span></span>, line 59, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/unittest/case.py<span class="pl-pds">"</span></span>, line 6, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    import logging
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/logging/__init__.py<span class="pl-pds">"</span></span>, line 28, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from string import Template
ImportError: cannot import name <span class="pl-s"><span class="pl-pds">'</span>Template<span class="pl-pds">'</span></span>
Error <span class="pl-k">in</span> sys.excepthook:
Traceback (most recent call last):
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3/dist-packages/apport_python_hook.py<span class="pl-pds">"</span></span>, line 63, <span class="pl-k">in</span> apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3/dist-packages/apport/__init__.py<span class="pl-pds">"</span></span>, line 5, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from apport.report import Report
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3/dist-packages/apport/report.py<span class="pl-pds">"</span></span>, line 21, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from urllib.request import urlopen
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/urllib/request.py<span class="pl-pds">"</span></span>, line 88, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    import http.client
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/http/client.py<span class="pl-pds">"</span></span>, line 71, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    import email.parser
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/email/parser.py<span class="pl-pds">"</span></span>, line 12, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from email.feedparser import FeedParser, BytesFeedParser
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/email/feedparser.py<span class="pl-pds">"</span></span>, line 27, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from email._policybase import compat32
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/email/_policybase.py<span class="pl-pds">"</span></span>, line 7, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from email import header
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/email/header.py<span class="pl-pds">"</span></span>, line 16, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    import email.quoprimime
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/email/quoprimime.py<span class="pl-pds">"</span></span>, line 44, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from string import ascii_letters, digits, hexdigits
ImportError: cannot import name <span class="pl-s"><span class="pl-pds">'</span>ascii_letters<span class="pl-pds">'</span></span>

Original exception was:
Traceback (most recent call last):
  File <span class="pl-s"><span class="pl-pds">"</span>/home/user/Desktop/string.py<span class="pl-pds">"</span></span>, line 1, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    import numpy as np
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/local/lib/python3.6/dist-packages/numpy/__init__.py<span class="pl-pds">"</span></span>, line 228, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from .testing import Tester
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/local/lib/python3.6/dist-packages/numpy/testing/__init__.py<span class="pl-pds">"</span></span>, line 10, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from unittest import TestCase
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/unittest/__init__.py<span class="pl-pds">"</span></span>, line 59, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/unittest/case.py<span class="pl-pds">"</span></span>, line 6, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    import logging
  File <span class="pl-s"><span class="pl-pds">"</span>/usr/lib/python3.6/logging/__init__.py<span class="pl-pds">"</span></span>, line 28, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    from string import Template
ImportError: cannot import name <span class="pl-s"><span class="pl-pds">'</span>Template<span class="pl-pds">'</span></span></pre></div>
<h3 dir="auto">Numpy/Python version information:</h3>
<p dir="auto">Numpy: 1.18.2<br>
Python: 3.6.9<br>
GCC 8.4.0</p>
<h3 dir="auto">Operating system:</h3>
<p dir="auto">Ubuntu 18.04.4 LTS</p>