a
    ‡ù»jhb  ã                   @   s‚  d dl mZ d dlZd dlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZ d dlmZmZ ddlmZ ddlmZmZ ddlmZ dd	lmZmZ dd
lmZmZ ddl m!Z! ddl"m#Z#m$Z$ d dlm%Z% g d¢Z&e 'd¡j(Z(e 'd¡j(Z)ddd dd ddœZ*dd„ Z+d1dd„Z,dd„ Z-d2dd„Z.dd„ Z/dd„ Z0dd „ Z1d!d"„ Z2d#d$„ Z3d%d&„ Z4d'd(„ Z5d)d*„ Z6d3d+d,„Z7d4d-d.„Z8d/d0„ Z9dS )5é    )ÚproductN)ÚdotÚdiagÚprodÚlogical_notÚravelÚ	transposeÚ	conjugateÚabsoluteÚamaxÚsignÚisfiniteÚtriu)ÚLinAlgErrorÚ	bandwidthé   )Únorm)ÚsolveÚinv)Úsvd)ÚschurÚrsf2csf)Úexpm_frechetÚ	expm_cond)Úsqrtm)Úpick_pade_structureÚpade_UV_calc)Úsingle)ÚexpmÚcosmÚsinmÚtanmÚcoshmÚsinhmÚtanhmÚlogmÚfunmÚsignmr   Úfractional_matrix_powerr   r   Ú
khatri_raoÚdÚf)ÚiÚlr+   r*   ÚFÚDc                 C   s8   t  | ¡} t| jƒdks,| jd | jd kr4tdƒ‚| S )aƒ  
    Wraps asarray with the extra requirement that the input be a square matrix.

    The motivation is that the matfuncs module has real functions that have
    been lifted to square matrix functions.

    Parameters
    ----------
    A : array_like
        A square matrix.

    Returns
    -------
    out : ndarray
        An ndarray copy or view or other representation of A.

    é   r   r   z expected square array_like input)ÚnpÚasarrayÚlenÚshapeÚ
ValueError©ÚA© r8   ú<E:\soccer\ml_env\Lib\site-packages\scipy/linalg/_matfuncs.pyÚ_asarray_square%   s    
"r:   c                 C   sV   t  | ¡rRt  |¡rR|du r:td td dœt|jj  }t j|j	d|d�rR|j
}|S )a(  
    Return either B or the real part of B, depending on properties of A and B.

    The motivation is that B has been computed as a complicated function of A,
    and B may be perturbed by negligible imaginary components.
    If A is real and B is complex with small imaginary components,
    then return a real copy of B.  The assumption in that case would be that
    the imaginary components of B are numerical artifacts.

    Parameters
    ----------
    A : ndarray
        Input array whose type is to be checked as real vs. complex.
    B : ndarray
        Array to be returned, possibly without its imaginary part.
    tol : float
        Absolute tolerance.

    Returns
    -------
    out : real or complex array
        Either the input array B or only the real part of the input array B.

    Nç     @�@g    €„.A©r   r   ç        )Zatol)r1   Z	isrealobjÚiscomplexobjÚfepsÚepsÚ_array_precisionÚdtypeÚcharZallcloseÚimagÚreal)r7   ÚBÚtolr8   r8   r9   Ú_maybe_real=   s    rH   c                 C   s    t | ƒ} ddl}|jj | |¡S )aò  
    Compute the fractional power of a matrix.

    Proceeds according to the discussion in section (6) of [1]_.

    Parameters
    ----------
    A : (N, N) array_like
        Matrix whose fractional power to evaluate.
    t : float
        Fractional power.

    Returns
    -------
    X : (N, N) array_like
        The fractional power of the matrix.

    References
    ----------
    .. [1] Nicholas J. Higham and Lijing lin (2011)
           "A Schur-Pade Algorithm for Fractional Powers of a Matrix."
           SIAM Journal on Matrix Analysis and Applications,
           32 (3). pp. 1056-1078. ISSN 0895-4798

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import fractional_matrix_power
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> b = fractional_matrix_power(a, 0.5)
    >>> b
    array([[ 0.75592895,  1.13389342],
           [ 0.37796447,  1.88982237]])
    >>> np.dot(b, b)      # Verify square root
    array([[ 1.,  3.],
           [ 1.,  4.]])

    r   N)r:   Úscipy.linalg._matfuncs_inv_ssqÚlinalgÚ_matfuncs_inv_ssqZ_fractional_matrix_power)r7   ÚtÚscipyr8   r8   r9   r(   c   s    )r(   Tc                 C   sz   t | ƒ} ddl}|jj | ¡}t| |ƒ}dt }tt|ƒ|  dƒt| dƒ }|rnt	|ƒr`||krjt
d|ƒ |S ||fS dS )a  
    Compute matrix logarithm.

    The matrix logarithm is the inverse of
    expm: expm(logm(`A`)) == `A`

    Parameters
    ----------
    A : (N, N) array_like
        Matrix whose logarithm to evaluate
    disp : bool, optional
        Print warning if error in the result is estimated large
        instead of returning estimated error. (Default: True)

    Returns
    -------
    logm : (N, N) ndarray
        Matrix logarithm of `A`
    errest : float
        (if disp == False)

        1-norm of the estimated error, ||err||_1 / ||A||_1

    References
    ----------
    .. [1] Awad H. Al-Mohy and Nicholas J. Higham (2012)
           "Improved Inverse Scaling and Squaring Algorithms
           for the Matrix Logarithm."
           SIAM Journal on Scientific Computing, 34 (4). C152-C169.
           ISSN 1095-7197

    .. [2] Nicholas J. Higham (2008)
           "Functions of Matrices: Theory and Computation"
           ISBN 978-0-898716-46-7

    .. [3] Nicholas J. Higham and Lijing lin (2011)
           "A Schur-Pade Algorithm for Fractional Powers of a Matrix."
           SIAM Journal on Matrix Analysis and Applications,
           32 (3). pp. 1056-1078. ISSN 0895-4798

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import logm, expm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> b = logm(a)
    >>> b
    array([[-1.02571087,  2.05142174],
           [ 0.68380725,  1.02571087]])
    >>> expm(b)         # Verify expm(logm(a)) returns a
    array([[ 1.,  3.],
           [ 1.,  4.]])

    r   Néè  r   z0logm result may be inaccurate, approximate err =)r:   rI   rJ   rK   Z_logmrH   r@   r   r   r   Úprint)r7   ÚdisprM   r.   ÚerrtolÚerrestr8   r8   r9   r%   ‘   s    7

r%   c              
   C   s†  t  | ¡}|jdkr6|jdk r6t  t  | ¡ ¡gg¡S |jdk rHtdƒ‚|jd |jd krdtdƒ‚|jd }t	|jŽ dkr†t  
|¡S |jdd… d	kr¢t  |¡S t  |jt j¡sÀ| t j¡}n|jt jkrØ| t j¡}|jd }t j|j|jd
�}t jd||f|jd
�}tdd„ |jdd… D ƒŽ D �]X}|| }t|ƒ}t|ƒ�sdt  t  t  |¡¡¡||< �q&||ddd…dd…f< t|ƒ\}}	|	dk�rÔ|dd…  d|	  ggd|	  ggd|	  ggd|	  ggg9  < t|||ƒ |d }
|	dk�r2|d dk�s|d dk�rt  |¡}t  |d|	   ¡t  d|
¡dd…< t j||d dk�rTdndd�}t|	d ddƒD ]ª}|
|
 }
t  |d|   ¡t  d|
¡dd…< t|d|   ƒ|d|    }|d dk�rð|t  d|
dd…dd…f ¡dd…< n$|t  d|
dd…dd…f ¡dd…< �qlnt|	ƒD ]}|
|
 }
�q"|d dk�sN|d dk�rv|d dk�rft  |
¡nt  |
¡||< n|
||< �q&|S )a�  Compute the matrix exponential of an array.

    Parameters
    ----------
    A : ndarray
        Input with last two dimensions are square ``(..., n, n)``.

    Returns
    -------
    eA : ndarray
        The resulting matrix exponential with the same shape of ``A``

    Notes
    -----
    Implements the algorithm given in [1], which is essentially a Pade
    approximation with a variable order that is decided based on the array
    data.

    For input with size ``n``, the memory usage is in the worst case in the
    order of ``8*(n**2)``. If the input data is not of single and double
    precision of real and complex dtypes, it is copied to a new array.

    For cases ``n >= 400``, the exact 1-norm computation cost, breaks even with
    1-norm estimation and from that point on the estimation scheme given in
    [2] is used to decide on the approximation order.

    References
    ----------
    .. [1] Awad H. Al-Mohy and Nicholas J. Higham, (2009), "A New Scaling
           and Squaring Algorithm for the Matrix Exponential", SIAM J. Matrix
           Anal. Appl. 31(3):970-989, :doi:`10.1137/09074721X`

    .. [2] Nicholas J. Higham and Francoise Tisseur (2000), "A Block Algorithm
           for Matrix 1-Norm Estimation, with an Application to 1-Norm
           Pseudospectra." SIAM J. Matrix Anal. Appl. 21(4):1185-1201,
           :doi:`10.1137/S0895479899356080`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import expm, sinm, cosm

    Matrix version of the formula exp(0) = 1:

    >>> expm(np.zeros((3, 2, 2)))
    array([[[1., 0.],
            [0., 1.]],
    <BLANKLINE>
           [[1., 0.],
            [0., 1.]],
    <BLANKLINE>
           [[1., 0.],
            [0., 1.]]])

    Euler's identity (exp(i*theta) = cos(theta) + i*sin(theta))
    applied to a matrix:

    >>> a = np.array([[1.0, 2.0], [-1.0, 3.0]])
    >>> expm(1j*a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])
    >>> cosm(a) + 1j*sinm(a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])

    r   r0   z0The input array must be at least two-dimensionaléÿÿÿÿéþÿÿÿz-Last 2 dimensions of the array must be squarer   N)r   r   )rB   é   c                 S   s   g | ]}t |ƒ‘qS r8   )Úrange)Ú.0Úxr8   r8   r9   Ú
<listcomp>;  ó    zexpm.<locals>.<listcomp>é   é   é@   zii->i)Úkg       @)r1   r2   ÚsizeÚndimÚarrayÚexpÚitemr   r4   ÚminZ
empty_likeZ
issubdtyperB   ZinexactÚastypeZfloat64Zfloat16Zfloat32Úemptyr   r   Úanyr   r   r   ZeinsumrV   Ú
_exp_sinchr   Ztril)r7   ÚaÚnZeAZAmÚindZawZluÚmÚsZeAwZdiag_awÚsdr,   Zexp_sdÚ_r8   r8   r9   r   Ø   sb    C





"

D

$ $ &*(r   c                 C   sX   t  t  | ¡¡}t  | ¡}|dk}||   ||    < t  | d d… | ¡||< |S )Nr=   rS   )r1   Údiffrb   )rX   Z	lexp_diffZl_diffZmask_zr8   r8   r9   rh   q  s    
rh   c                 C   s@   t | ƒ} t | ¡r.dtd|  ƒtd|  ƒ  S td|  ƒjS dS )a!  
    Compute the matrix cosine.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array

    Returns
    -------
    cosm : (N, N) ndarray
        Matrix cosine of A

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import expm, sinm, cosm

    Euler's identity (exp(i*theta) = cos(theta) + i*sin(theta))
    applied to a matrix:

    >>> a = np.array([[1.0, 2.0], [-1.0, 3.0]])
    >>> expm(1j*a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])
    >>> cosm(a) + 1j*sinm(a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])

    ç      à?ù              ð?ù       €      ð¿N)r:   r1   r>   r   rE   r6   r8   r8   r9   r   {  s    !
r   c                 C   s@   t | ƒ} t | ¡r.dtd|  ƒtd|  ƒ  S td|  ƒjS dS )a   
    Compute the matrix sine.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array.

    Returns
    -------
    sinm : (N, N) ndarray
        Matrix sine of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import expm, sinm, cosm

    Euler's identity (exp(i*theta) = cos(theta) + i*sin(theta))
    applied to a matrix:

    >>> a = np.array([[1.0, 2.0], [-1.0, 3.0]])
    >>> expm(1j*a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])
    >>> cosm(a) + 1j*sinm(a)
    array([[ 0.42645930+1.89217551j, -2.13721484-0.97811252j],
           [ 1.06860742+0.48905626j, -1.71075555+0.91406299j]])

    y       €      à¿rr   rs   N)r:   r1   r>   r   rD   r6   r8   r8   r9   r    £  s    !
r    c                 C   s    t | ƒ} t| tt| ƒt| ƒƒƒS )aÙ  
    Compute the matrix tangent.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array.

    Returns
    -------
    tanm : (N, N) ndarray
        Matrix tangent of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import tanm, sinm, cosm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> t = tanm(a)
    >>> t
    array([[ -2.00876993,  -8.41880636],
           [ -2.80626879, -10.42757629]])

    Verify tanm(a) = sinm(a).dot(inv(cosm(a)))

    >>> s = sinm(a)
    >>> c = cosm(a)
    >>> s.dot(np.linalg.inv(c))
    array([[ -2.00876993,  -8.41880636],
           [ -2.80626879, -10.42757629]])

    )r:   rH   r   r   r    r6   r8   r8   r9   r!   Ë  s    #r!   c                 C   s$   t | ƒ} t| dt| ƒt|  ƒ  ƒS )a  
    Compute the hyperbolic matrix cosine.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array.

    Returns
    -------
    coshm : (N, N) ndarray
        Hyperbolic matrix cosine of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import tanhm, sinhm, coshm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> c = coshm(a)
    >>> c
    array([[ 11.24592233,  38.76236492],
           [ 12.92078831,  50.00828725]])

    Verify tanhm(a) = sinhm(a).dot(inv(coshm(a)))

    >>> t = tanhm(a)
    >>> s = sinhm(a)
    >>> t - s.dot(np.linalg.inv(c))
    array([[  2.72004641e-15,   4.55191440e-15],
           [  0.00000000e+00,  -5.55111512e-16]])

    rq   ©r:   rH   r   r6   r8   r8   r9   r"   ò  s    #r"   c                 C   s$   t | ƒ} t| dt| ƒt|  ƒ  ƒS )a  
    Compute the hyperbolic matrix sine.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array.

    Returns
    -------
    sinhm : (N, N) ndarray
        Hyperbolic matrix sine of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import tanhm, sinhm, coshm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> s = sinhm(a)
    >>> s
    array([[ 10.57300653,  39.28826594],
           [ 13.09608865,  49.86127247]])

    Verify tanhm(a) = sinhm(a).dot(inv(coshm(a)))

    >>> t = tanhm(a)
    >>> c = coshm(a)
    >>> t - s.dot(np.linalg.inv(c))
    array([[  2.72004641e-15,   4.55191440e-15],
           [  0.00000000e+00,  -5.55111512e-16]])

    rq   rt   r6   r8   r8   r9   r#     s    #r#   c                 C   s    t | ƒ} t| tt| ƒt| ƒƒƒS )a  
    Compute the hyperbolic matrix tangent.

    This routine uses expm to compute the matrix exponentials.

    Parameters
    ----------
    A : (N, N) array_like
        Input array

    Returns
    -------
    tanhm : (N, N) ndarray
        Hyperbolic matrix tangent of `A`

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import tanhm, sinhm, coshm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> t = tanhm(a)
    >>> t
    array([[ 0.3428582 ,  0.51987926],
           [ 0.17329309,  0.86273746]])

    Verify tanhm(a) = sinhm(a).dot(inv(coshm(a)))

    >>> s = sinhm(a)
    >>> c = coshm(a)
    >>> t - s.dot(np.linalg.inv(c))
    array([[  2.72004641e-15,   4.55191440e-15],
           [  0.00000000e+00,  -5.55111512e-16]])

    )r:   rH   r   r"   r#   r6   r8   r8   r9   r$   @  s    #r$   c              	   C   s2  t | ƒ} t| ƒ\}}t||ƒ\}}|j\}}t|t|ƒƒƒ}| |jj¡}t|d ƒ}t	d|ƒD �]}t	d|| d ƒD ]þ}	|	| }
||	d |
d f ||
d |
d f ||	d |	d f   }t
|	|
d ƒ}t||	d |f |||
d f ƒt||	d |f |||
d f ƒ }|| }||
d |
d f ||	d |	d f  }|dk�rT|| }|||	d |
d f< t|t|ƒƒ}qxq`tt||ƒtt|ƒƒƒ}t| |ƒ}ttdœt|jj  }|dk�rÀ|}tdt||| tt|dƒdƒ ƒƒ}tttt|ƒƒƒdd��rtj}|�r&|d| k�r"td|ƒ |S ||fS d	S )
a–  
    Evaluate a matrix function specified by a callable.

    Returns the value of matrix-valued function ``f`` at `A`. The
    function ``f`` is an extension of the scalar-valued function `func`
    to matrices.

    Parameters
    ----------
    A : (N, N) array_like
        Matrix at which to evaluate the function
    func : callable
        Callable object that evaluates a scalar function f.
        Must be vectorized (eg. using vectorize).
    disp : bool, optional
        Print warning if error in the result is estimated large
        instead of returning estimated error. (Default: True)

    Returns
    -------
    funm : (N, N) ndarray
        Value of the matrix function specified by func evaluated at `A`
    errest : float
        (if disp == False)

        1-norm of the estimated error, ||err||_1 / ||A||_1

    Notes
    -----
    This function implements the general algorithm based on Schur decomposition
    (Algorithm 9.1.1. in [1]_).

    If the input matrix is known to be diagonalizable, then relying on the
    eigendecomposition is likely to be faster. For example, if your matrix is
    Hermitian, you can do

    >>> from scipy.linalg import eigh
    >>> def funm_herm(a, func, check_finite=False):
    ...     w, v = eigh(a, check_finite=check_finite)
    ...     ## if you further know that your matrix is positive semidefinite,
    ...     ## you can optionally guard against precision errors by doing
    ...     # w = np.maximum(w, 0)
    ...     w = func(w)
    ...     return (v * w).dot(v.conj().T)

    References
    ----------
    .. [1] Gene H. Golub, Charles F. van Loan, Matrix Computations 4th ed.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.linalg import funm
    >>> a = np.array([[1.0, 3.0], [1.0, 4.0]])
    >>> funm(a, lambda x: x*x)
    array([[  4.,  15.],
           [  5.,  19.]])
    >>> a.dot(a)
    array([[  4.,  15.],
           [  5.,  19.]])

    )r   r   r   r=   r<   r   )ZaxisrN   z0funm result may be inaccurate, approximate err =N)r:   r   r   r4   r   re   rB   rC   ÚabsrV   Úslicer   rd   r   r	   rH   r?   r@   rA   Úmaxr   r   r   r   r   r   r1   ÚinfrO   )r7   ÚfuncrP   ÚTÚZrj   r.   ZmindenÚpr,   Újrm   ZkslÚvalZdenrG   Úerrr8   r8   r9   r&   g  s@    ?
<D(


$
r&   c                 C   s  t | ƒ} dd„ }t| |dd�\}}dt dt dœt|jj  }||k rL|S t| dd�}t 	|¡}d	| }| |t 
| jd ¡  }	|}
td
ƒD ]V}t|	ƒ}d	|	|  }	d	t|	|	ƒ|	  }tt||ƒ| dƒ}||k sÜ|
|krà qæ|}
qŽ|�rt|ƒrþ||k�rtd|ƒ |	S |	|fS dS )a'  
    Matrix sign function.

    Extension of the scalar sign(x) to matrices.

    Parameters
    ----------
    A : (N, N) array_like
        Matrix at which to evaluate the sign function
    disp : bool, optional
        Print warning if error in the result is estimated large
        instead of returning estimated error. (Default: True)

    Returns
    -------
    signm : (N, N) ndarray
        Value of the sign function at `A`
    errest : float
        (if disp == False)

        1-norm of the estimated error, ||err||_1 / ||A||_1

    Examples
    --------
    >>> from scipy.linalg import signm, eigvals
    >>> a = [[1,2,3], [1,2,1], [1,1,1]]
    >>> eigvals(a)
    array([ 4.12488542+0.j, -0.76155718+0.j,  0.63667176+0.j])
    >>> eigvals(signm(a))
    array([-1.+0.j,  1.+0.j,  1.+0.j])

    c                 S   sL   t  | ¡}|jjdkr(dt t| ƒ }ndt t| ƒ }tt|ƒ|k| ƒS )Nr+   r;   )	r1   rE   rB   rC   r?   r   r@   r   r
   )rX   ÚrxÚcr8   r8   r9   Úrounded_signó  s
    
zsignm.<locals>.rounded_signr   )rP   r;   r<   F)Z
compute_uvrq   éd   r   z1signm result may be inaccurate, approximate err =N)r:   r&   r?   r@   rA   rB   rC   r   r1   r   Úidentityr4   rV   r   r   r   r   rO   )r7   rP   r‚   ÚresultrR   rQ   ÚvalsZmax_svr�   ZS0Zprev_errestr,   ZiS0ZPpr8   r8   r9   r'   Ð  s0    !

r'   c                 C   s˜   t  | ¡} t  |¡}| jdkr(|jdks0tdƒ‚| jd |jd ksLtdƒ‚| ddd…t jdd…f |dt jdd…dd…f  }| d|jdd…  ¡S )aù  
    Khatri-rao product

    A column-wise Kronecker product of two matrices

    Parameters
    ----------
    a : (n, k) array_like
        Input array
    b : (m, k) array_like
        Input array

    Returns
    -------
    c:  (n*m, k) ndarray
        Khatri-rao product of `a` and `b`.

    See Also
    --------
    kron : Kronecker product

    Notes
    -----
    The mathematical definition of the Khatri-Rao product is:

    .. math::

        (A_{ij}  \bigotimes B_{ij})_{ij}

    which is the Kronecker product of every column of A and B, e.g.::

        c = np.vstack([np.kron(a[:, k], b[:, k]) for k in range(b.shape[1])]).T

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import linalg
    >>> a = np.array([[1, 2, 3], [4, 5, 6]])
    >>> b = np.array([[3, 4, 5], [6, 7, 8], [2, 3, 9]])
    >>> linalg.khatri_rao(a, b)
    array([[ 3,  8, 15],
           [ 6, 14, 24],
           [ 2,  6, 27],
           [12, 20, 30],
           [24, 35, 48],
           [ 8, 15, 54]])

    r0   z(The both arrays should be 2-dimensional.r   z6The number of columns for both arrays should be equal..N)rS   )r1   r2   r`   r5   r4   ZnewaxisZreshape)ri   Úbr�   r8   r8   r9   r)      s    1

4r)   )N)T)T)T):Ú	itertoolsr   Únumpyr1   r   r   r   r   r   r   r	   r
   r   r   r   r   Zscipy.linalgr   r   Z_miscr   Z_basicr   r   Z_decomp_svdr   Z_decomp_schurr   r   Z_expm_frechetr   r   Z_matfuncs_sqrtmr   Z_matfuncs_expmr   r   r   Ú__all__Zfinfor@   r?   rA   r:   rH   r(   r%   r   rh   r   r    r!   r"   r#   r$   r&   r'   r)   r8   r8   r8   r9   Ú<module>   s>   8
&.
G 
((''''
i
P