(*matrices)
return matrix_expansion
Compute the tensor product of a sequence of sympy Matrices.

    This is the standard Kronecker product of matrices [1].

    Parameters
    ==========

    matrices : tuple of Matrix instances
        The matrices to take the tensor product of.

    Returns
    =======

    matrix : Matrix
        The tensor product matrix.

    Examples
    ========

    >>> from sympy import I, Matrix, symbols
    >>> from sympy.physics.quantum.matrixutils import _sympy_tensor_product

    >>> m1 = Matrix([[1,2],[3,4]])
    >>> m2 = Matrix([[1,0],[0,1]])
    >>> _sympy_tensor_product(m1, m2)
    Matrix([
    [1, 0, 2, 0],
    [0, 1, 0, 2],
    [3, 0, 4, 0],
    [0, 3, 0, 4]])
    >>> _sympy_tensor_product(m2, m1)
    Matrix([
    [1, 2, 0, 0],
    [3, 4, 0, 0],
    [0, 0, 1, 2],
    [0, 0, 3, 4]])

    References
    ==========

    [1] http://en.wikipedia.org/wiki/Kronecker_product
Compute the tensor product of a sequence of sympy Matrices.
Compute the tensor product of a sequence of sympy Matrices .
def _sympy_tensor_product(*matrices):
    """Compute the tensor product of a sequence of sympy Matrices.

    This is the standard Kronecker product of matrices [1].

    Parameters
    ==========

    matrices : tuple of Matrix instances
        The matrices to take the tensor product of.

    Returns
    =======

    matrix : Matrix
        The tensor product matrix.

    Examples
    ========

    >>> from sympy import I, Matrix, symbols
    >>> from sympy.physics.quantum.matrixutils import _sympy_tensor_product

    >>> m1 = Matrix([[1,2],[3,4]])
    >>> m2 = Matrix([[1,0],[0,1]])
    >>> _sympy_tensor_product(m1, m2)
    Matrix([
    [1, 0, 2, 0],
    [0, 1, 0, 2],
    [3, 0, 4, 0],
    [0, 3, 0, 4]])
    >>> _sympy_tensor_product(m2, m1)
    Matrix([
    [1, 2, 0, 0],
    [3, 4, 0, 0],
    [0, 0, 1, 2],
    [0, 0, 3, 4]])

    References
    ==========

    [1] http://en.wikipedia.org/wiki/Kronecker_product
    """
    # Make sure we have a sequence of Matrices
    if not all(isinstance(m, Matrix) for m in matrices):
        raise TypeError(
            'Sequence of Matrices expected, got: %s' % repr(matrices)
        )

    # Pull out the first element in the product.
    matrix_expansion = matrices[-1]
    # Do the tensor product working from right to left.
    for mat in reversed(matrices[:-1]):
        rows = mat.rows
        cols = mat.cols
        # Go through each row appending tensor product to.
        # running matrix_expansion.
        for i in range(rows):
            start = matrix_expansion*mat[i*cols]
            # Go through each column joining each item
            for j in range(cols - 1):
                start = start.row_join(
                    matrix_expansion*mat[i*cols + j + 1]
                )
            # If this is the first element, make it the start of the
            # new row.
            if i == 0:
                next = start
            else:
                next = next.col_join(start)
        matrix_expansion = next
    return matrix_expansion
def _sympy_tensor_product ( * matrices ) : # Make sure we have a sequence of Matrices if not all ( isinstance ( m , Matrix ) for m in matrices ) : raise TypeError ( 'Sequence of Matrices expected, got: %s' % repr ( matrices ) ) # Pull out the first element in the product. matrix_expansion = matrices [ - 1 ] # Do the tensor product working from right to left. for mat in reversed ( matrices [ : - 1 ] ) : rows = mat . rows cols = mat . cols # Go through each row appending tensor product to. # running matrix_expansion. for i in range ( rows ) : start = matrix_expansion * mat [ i * cols ] # Go through each column joining each item for j in range ( cols - 1 ) : start = start . row_join ( matrix_expansion * mat [ i * cols + j + 1 ] ) # If this is the first element, make it the start of the # new row. if i == 0 : next = start else : next = next . col_join ( start ) matrix_expansion = next return matrix_expansion