Author: bugman Date: Mon Jun 8 16:21:38 2009 New Revision: 9068 URL: http://svn.gna.org/viewcvs/relax?rev=9068&view=rev Log: Added a function for calculating the Kronecker product. Added: 1.3/maths_fns/kronecker_product.py Added: 1.3/maths_fns/kronecker_product.py URL: http://svn.gna.org/viewcvs/relax/1.3/maths_fns/kronecker_product.py?rev=9068&view=auto ============================================================================== --- 1.3/maths_fns/kronecker_product.py (added) +++ 1.3/maths_fns/kronecker_product.py Mon Jun 8 16:21:38 2009 @@ -1,0 +1,22 @@ +from numpy import concatenate, outer + + +def kron_prod(A, B): + """Calculate the Kronecker product of the matrices A and B. + + @param A: ixj matrix. + @type A: rank-2 numpy array + @param B: kxl matrix. + @type B: rank-2 numpy array + @return: The Kronecker product. + @rtype: ikxjl rank-2 numpy array + """ + + # The outer product. + C = outer(A, B) + + # Redefine the shape. + C.shape = A.shape + B.shape + + # Generate and return the Kronecker product matrix. + return concatenate(concatenate(C, axis=1), axis=1)