<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/930" rel="nofollow">http://projects.scipy.org/numpy/ticket/930</a> on 2008-10-14 by trac user jbosch, assigned to unknown.</em></p>
<p dir="auto">The <code class="notranslate">empty_like</code> and <code class="notranslate">zeros_like</code> creation functions, which are defined in python in numeric.py, differ in their handling of array-subtype input from <code class="notranslate">ones_like</code>, which is defined in C as a ufunc.</p>
<p dir="auto">In particular, if a subtype of ndarray is passed to <code class="notranslate">empty_like</code> or <code class="notranslate">zeros_like</code>, neither <code class="notranslate">__array_wrap__</code> or <code class="notranslate">__array_finalize__</code> is called, which makes it impossible for subtypes to define any extra attributes they might need.</p>
<p dir="auto">I believe this behavior could be fixed entirely by switching from:</p>
<p dir="auto"><code class="notranslate">if isinstance(a,ndarray):</code></p>
<p dir="auto">to</p>
<p dir="auto"><code class="notranslate">if type(a)==ndarray:</code></p>
<p dir="auto">at the top of those two functions, though there are probably more efficient ways to accomplish the same thing.</p>
<p dir="auto">Copied code for NumPy.ipmt at <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ipmt.html#numpy.ipmt" rel="nofollow">https://docs.scipy.org/doc/numpy/reference/generated/numpy.ipmt.html#numpy.ipmt</a>.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
principal = 2500.00
per = np.arange(1*12) + 1
ipmt = np.ipmt(0.0824/12, per, 1*12, principal)
ppmt = np.ppmt(0.0824/12, per, 1*12, principal)
fmt = '{0:2d} {1:8.2f} {2:8.2f} {3:8.2f}'
for payment in per:
    index = payment - 1
    principal = principal + ppmt[index]
    print(fmt.format(payment, ppmt[index], ipmt[index], principal))"><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">principal</span> <span class="pl-c1">=</span> <span class="pl-c1">2500.00</span>
<span class="pl-s1">per</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">1</span><span class="pl-c1">*</span><span class="pl-c1">12</span>) <span class="pl-c1">+</span> <span class="pl-c1">1</span>
<span class="pl-s1">ipmt</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ipmt</span>(<span class="pl-c1">0.0824</span><span class="pl-c1">/</span><span class="pl-c1">12</span>, <span class="pl-s1">per</span>, <span class="pl-c1">1</span><span class="pl-c1">*</span><span class="pl-c1">12</span>, <span class="pl-s1">principal</span>)
<span class="pl-s1">ppmt</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ppmt</span>(<span class="pl-c1">0.0824</span><span class="pl-c1">/</span><span class="pl-c1">12</span>, <span class="pl-s1">per</span>, <span class="pl-c1">1</span><span class="pl-c1">*</span><span class="pl-c1">12</span>, <span class="pl-s1">principal</span>)
<span class="pl-s1">fmt</span> <span class="pl-c1">=</span> <span class="pl-s">'{0:2d} {1:8.2f} {2:8.2f} {3:8.2f}'</span>
<span class="pl-k">for</span> <span class="pl-s1">payment</span> <span class="pl-c1">in</span> <span class="pl-s1">per</span>:
    <span class="pl-s1">index</span> <span class="pl-c1">=</span> <span class="pl-s1">payment</span> <span class="pl-c1">-</span> <span class="pl-c1">1</span>
    <span class="pl-s1">principal</span> <span class="pl-c1">=</span> <span class="pl-s1">principal</span> <span class="pl-c1">+</span> <span class="pl-s1">ppmt</span>[<span class="pl-s1">index</span>]
    <span class="pl-en">print</span>(<span class="pl-s1">fmt</span>.<span class="pl-en">format</span>(<span class="pl-s1">payment</span>, <span class="pl-s1">ppmt</span>[<span class="pl-s1">index</span>], <span class="pl-s1">ipmt</span>[<span class="pl-s1">index</span>], <span class="pl-s1">principal</span>))</pre></div>
<p dir="auto">Expected output:</p>
<p dir="auto">1   -200.58    -17.17   2299.42<br>
2   -201.96    -15.79   2097.46<br>
3   -203.35    -14.40   1894.11<br>
4   -204.74    -13.01   1689.37<br>
5   -206.15    -11.60   1483.22<br>
6   -207.56    -10.18   1275.66<br>
7   -208.99    -8.76     1066.67<br>
8   -210.42    -7.32      856.25<br>
9   -211.87    -5.88      644.38<br>
10   -213.32   -4.42      431.05<br>
11   -214.79   -2.96      216.26<br>
12  -216.26    -1.49     -0.00</p>
<p dir="auto">I get:</p>
<p dir="auto">0      -216.26        -1.49         2283.74<br>
1      -199.21       -18.53        2084.52<br>
2      -200.58       -17.17        1883.94<br>
3      -201.96       -15.79        1681.98<br>
4      -203.35       -14.40        1478.64<br>
5      -204.74       -13.01        1273.89<br>
6      -206.15       -11.60        1067.74<br>
7      -207.56       -10.18         860.18<br>
8      -208.99        -8.76          651.19<br>
9      -210.42        -7.32          440.77<br>
10      -211.87        -5.88         228.90<br>
11      -213.32        -4.42         15.57<br>
12      -214.79        -2.96        -199.21</p>
<p dir="auto">per variable is supposed to start the payment number count at 1, but as you can see, when I do it, it starts at 0 and throws off the entire array.</p>
<h3 dir="auto">Numpy version information: 1.17.0</h3>
<h3 dir="auto">Python version information: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]</h3>
<p dir="auto">How do I get an accurate array?<br>
Thank you.</p>