<p dir="auto">I noticed that there seems to be an overflow happening with <code class="notranslate">numpy.linalg.matrix_power</code> when using large exponents.</p>
<p dir="auto">In my opinion, this should at least raise an <code class="notranslate">OverflowError</code>.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="np.version.git_revision
Out[8]: '68538b74483009c2c2d1644ef00397014f95a696'
np.version.full_version == '1.6.1'

In [10]: A
Out[10]: 
array([[1, 2],
       [1, 0]])

In [11]: np.linalg.matrix_power(A, 100)
Out[11]: 
array([[-6148914691236517205, -6148914691236517206],
       [ 6148914691236517205,  6148914691236517206]])"><pre class="notranslate"><code class="notranslate">np.version.git_revision
Out[8]: '68538b74483009c2c2d1644ef00397014f95a696'
np.version.full_version == '1.6.1'

In [10]: A
Out[10]: 
array([[1, 2],
       [1, 0]])

In [11]: np.linalg.matrix_power(A, 100)
Out[11]: 
array([[-6148914691236517205, -6148914691236517206],
       [ 6148914691236517205,  6148914691236517206]])
</code></pre></div>
<p dir="auto">I noticed that the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.MaskedArray.mean.html#numpy.ma.MaskedArray.mean" rel="nofollow">numpy masked-array mean method</a> returns different types when it probably should not:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import sys
sys.version
#'2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'
import numpy as np
np.__version__
#'1.9.2'

A = np.ma.masked_equal([1,1,0], value=0)
B = np.ma.masked_equal([1,1,1], value=0) # no masked values

type(A.mean())
#numpy.float64
type(B.mean())
#numpy.ma.core.MaskedArray"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">sys</span>
<span class="pl-s1">sys</span>.<span class="pl-s1">version</span>
<span class="pl-c">#'2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'</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">np</span>.<span class="pl-s1">__version__</span>
<span class="pl-c">#'1.9.2'</span>

<span class="pl-v">A</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">ma</span>.<span class="pl-en">masked_equal</span>([<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">0</span>], <span class="pl-s1">value</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
<span class="pl-v">B</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">ma</span>.<span class="pl-en">masked_equal</span>([<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>], <span class="pl-s1">value</span><span class="pl-c1">=</span><span class="pl-c1">0</span>) <span class="pl-c"># no masked values</span>

<span class="pl-en">type</span>(<span class="pl-v">A</span>.<span class="pl-en">mean</span>())
<span class="pl-c">#numpy.float64</span>
<span class="pl-en">type</span>(<span class="pl-v">B</span>.<span class="pl-en">mean</span>())
<span class="pl-c">#numpy.ma.core.MaskedArray</span></pre></div>
<p dir="auto">Other <code class="notranslate">numpy.ma.core.MaskedArray</code> methods seem to be consistent</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="type( A.sum()) == type(B.sum())
# True
type( A.prod()) == type(B.prod())
# True
type( A.std()) == type(B.std())
# True
type( A.mean()) == type(B.mean())
# False"><pre class="notranslate"><span class="pl-en">type</span>( <span class="pl-v">A</span>.<span class="pl-en">sum</span>()) <span class="pl-c1">==</span> <span class="pl-en">type</span>(<span class="pl-v">B</span>.<span class="pl-en">sum</span>())
<span class="pl-c"># True</span>
<span class="pl-en">type</span>( <span class="pl-v">A</span>.<span class="pl-en">prod</span>()) <span class="pl-c1">==</span> <span class="pl-en">type</span>(<span class="pl-v">B</span>.<span class="pl-en">prod</span>())
<span class="pl-c"># True</span>
<span class="pl-en">type</span>( <span class="pl-v">A</span>.<span class="pl-en">std</span>()) <span class="pl-c1">==</span> <span class="pl-en">type</span>(<span class="pl-v">B</span>.<span class="pl-en">std</span>())
<span class="pl-c"># True</span>
<span class="pl-en">type</span>( <span class="pl-v">A</span>.<span class="pl-en">mean</span>()) <span class="pl-c1">==</span> <span class="pl-en">type</span>(<span class="pl-v">B</span>.<span class="pl-en">mean</span>())
<span class="pl-c"># False</span></pre></div>
<p dir="auto">This kind of behavior seems undesirable.</p>
<p dir="auto">It is worth pointing out that</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="C = np.ma.masked_array([1, 1, 1], mask=[False, False, False])
type(C.mean()) == type(A.mean())
# True "><pre class="notranslate"><span class="pl-v">C</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">ma</span>.<span class="pl-en">masked_array</span>([<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">1</span>], <span class="pl-s1">mask</span><span class="pl-c1">=</span>[<span class="pl-c1">False</span>, <span class="pl-c1">False</span>, <span class="pl-c1">False</span>])
<span class="pl-en">type</span>(<span class="pl-v">C</span>.<span class="pl-en">mean</span>()) <span class="pl-c1">==</span> <span class="pl-en">type</span>(<span class="pl-v">A</span>.<span class="pl-en">mean</span>())
<span class="pl-c"># True </span></pre></div>
<p dir="auto">You can see my original stack overflow question <a href="http://stackoverflow.com/questions/38164773/numpy-ma-masked-array-mean-method-has-inconsitent-return-type" rel="nofollow">here</a></p>