Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Kronecker Power of sparse matrices problem

Why the following code does not work? I try it also in loops.

import numpy
from scipy import sparse
from scipy.sparse import coo_matrix

def SparseMatrixPower(A,p):
    if p == 1: 
        return(A)
    elif Mod(p,2):
        return(SparseMatrixProduct(A,SparseMatrixPower(A,A)), (p - 1) / 2)  
    else:
        return(SparseMatrixPower(SparseMatrixPower(A,A), p / 2))

def SparseMatrixProduct(A,B):
        return(sparse.kron(A,B)+sparse.kronsum(A,B))
A=sparse.coo_matrix([[0,1,2],[1,1,2],[2,2,3]])
B=sparse.coo_matrix([[0,1,2],[1,1,2],[2,2,3]])
SparseMatrixProduct(A,B)
SparseMatrixPower(A,3)

Kronecker Power of sparse matrices problem

Why the following code does not work? I try it also in loops.

import numpy
 from scipy import sparse
 from scipy.sparse import coo_matrix

def SparseMatrixPower(A,p):
    if p == 1: 
        return(A)
    elif Mod(p,2):
        return(SparseMatrixProduct(A,SparseMatrixPower(A,A)), return(SparseMatrixPower(A,SparseMatrixProduct(A,A)), (p - 1) / 2)  
    else:
        return(SparseMatrixPower(SparseMatrixPower(A,A), return(SparseMatrixPower(SparseMatrixProduct(A,A), p / 2))

def SparseMatrixProduct(A,B):
        return(sparse.kron(A,B)+sparse.kronsum(A,B))
 A=sparse.coo_matrix([[0,1,2],[1,1,2],[2,2,3]])
B=sparse.coo_matrix([[0,1,2],[1,1,2],[2,2,3]])
SparseMatrixProduct(A,B)
SparseMatrixPower(A,3)