<h3 dir="auto">Describe your issue.</h3>
<p dir="auto">** operator raises a sparse matrix to a power, but it is element-wise power when we use it on .A of the same sparse matrix.<br>
I am not sure this is a bug in numpy or scipy, or if it is intentional.<br>
It at least looks like an inconsistency between numpy arrays and scipy.sparse</p>
<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 scipy.sparse as sp

someMatrix = sp.csc_matrix(([1, -1], ([0, 1], [1, 0])), shape=(2, 2))

# print the matrix
print(someMatrix.A)

# raises the matrix to a power
print((someMatrix**2).A)

# element-wise power
print((someMatrix.A)**2)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">scipy</span>.<span class="pl-s1">sparse</span> <span class="pl-k">as</span> <span class="pl-s1">sp</span>

<span class="pl-s1">someMatrix</span> <span class="pl-c1">=</span> <span class="pl-s1">sp</span>.<span class="pl-en">csc_matrix</span>(([<span class="pl-c1">1</span>, <span class="pl-c1">-</span><span class="pl-c1">1</span>], ([<span class="pl-c1">0</span>, <span class="pl-c1">1</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">0</span>])), <span class="pl-s1">shape</span><span class="pl-c1">=</span>(<span class="pl-c1">2</span>, <span class="pl-c1">2</span>))

<span class="pl-c"># print the matrix</span>
<span class="pl-en">print</span>(<span class="pl-s1">someMatrix</span>.<span class="pl-v">A</span>)

<span class="pl-c"># raises the matrix to a power</span>
<span class="pl-en">print</span>((<span class="pl-s1">someMatrix</span><span class="pl-c1">**</span><span class="pl-c1">2</span>).<span class="pl-v">A</span>)

<span class="pl-c"># element-wise power</span>
<span class="pl-en">print</span>((<span class="pl-s1">someMatrix</span>.<span class="pl-v">A</span>)<span class="pl-c1">**</span><span class="pl-c1">2</span>)</pre></div>
<h3 dir="auto">Error message</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="No error messages."><pre class="notranslate">No error messages.</pre></div>
<h3 dir="auto">SciPy/NumPy/Python version information</h3>
<p dir="auto">1.8.0/1.22.1/3.10.1</p>
<h3 dir="auto">Describe your issue.</h3>
<p dir="auto">Currently, applying the <code class="notranslate">**</code> operator to a sparse array implements the <code class="notranslate">numpy.linalg.matrix_power</code> function. This is not compatible with the <code class="notranslate">np.array</code> implementation of <code class="notranslate">**</code>, which does element-wise power. This should be fixed as part of the migration from sparse "matrices" to sparse "arrays". Additionally, the <code class="notranslate">matrix_power</code> function should then also be included in the <code class="notranslate">sparse.linalg</code> package.</p>
<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="from scipy.sparse import csr_array, random

A = csr_array(random(5,5,0.1))
print(A.A)  
print((A**2).A)  #This does matrix_power, eventhough it is initialised as a sparse array (not a matrix)
print((A.A)**2)  #This does element-wise power, since it is a numpy array"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">scipy</span>.<span class="pl-s1">sparse</span> <span class="pl-k">import</span> <span class="pl-s1">csr_array</span>, <span class="pl-s1">random</span>

<span class="pl-v">A</span> <span class="pl-c1">=</span> <span class="pl-en">csr_array</span>(<span class="pl-en">random</span>(<span class="pl-c1">5</span>,<span class="pl-c1">5</span>,<span class="pl-c1">0.1</span>))
<span class="pl-en">print</span>(<span class="pl-v">A</span>.<span class="pl-v">A</span>)  
<span class="pl-en">print</span>((<span class="pl-v">A</span><span class="pl-c1">**</span><span class="pl-c1">2</span>).<span class="pl-v">A</span>)  <span class="pl-c">#This does matrix_power, eventhough it is initialised as a sparse array (not a matrix)</span>
<span class="pl-en">print</span>((<span class="pl-v">A</span>.<span class="pl-v">A</span>)<span class="pl-c1">**</span><span class="pl-c1">2</span>)  <span class="pl-c">#This does element-wise power, since it is a numpy array</span></pre></div>
<h3 dir="auto">Error message</h3>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="N/A"><pre class="notranslate">N/A</pre></div>
<h3 dir="auto">SciPy/NumPy/Python version information</h3>
<p dir="auto">1.8.0 1.20.3 sys.version_info(major=3, minor=9, micro=7, releaselevel='final', serial=0)</p>