Q:

Scipy gives wrong result for matrix multiplication

I am using scipy to do matrix multiplication of sparse matrix. For some reason, .power() method doesn't work for sparse matrix. I have checked it using three methods:
Here's my code:
import scipy as sp
import scipy.sparse 

Method1: Plain matrix multiplication
row = np.array([0, 3, 1, 0])
col = np.array([0, 3, 1, 2])
data = np.array([4, 5, 7, 9])
P1 = sp.sparse.coo_matrix((data, (row, col)), shape=(4, 4))
#Method 1
P1.power(4).todense() #gives wrong result

Result:
matrix([[ 256,    0, 6561,    0],  #6561 isn't right
        [   0, 2401,    0,    0],
        [   0,    0,    0,    0],
        [   0,    0,    0,  625]], dtype=int32)

Method 2:
P = P1.copy()
#calculate ^4
for loop in range(2):
    P = P.dot(P)
P.todense()

Output
matrix([[ 256,    0,  576,    0],
        [   0, 2401,    0,    0],
        [   0,    0,    0,    0],
        [   0,    0,    0,  625]], dtype=int32)

Method3
P1.dot(P1).dot(P1).dot(P1).todense()

Output:
matrix([[ 256,    0,  576,    0],
        [   0, 2401,    0,    0],
        [   0,    0,    0,    0],
        [   0,    0,    0,  625]], dtype=int32)

Method 4:
One can check the result at this website (symbolab.com) 

Other threads on this topic (Element-wise power of scipy.sparse matrix, Matrix power for sparse matrix in python), focus on how to do matrix multiplication. I'd appreciate any help.

A:

You could use ** notation:
(P1**4).todense()

Result:
[[ 256    0  576    0]
 [   0 2401    0    0]
 [   0    0    0    0]
 [   0    0    0  625]]

EDIT: Regarding why .power() doesn't return the expected result:
— as Zinki mentioned in their comment:

p.power(2) is "element-wise power". 9**4 = 6561.

