Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? Coder avec une
Intelligence Artificielle
Voir le programme détaillé
Module « scipy.sparse.linalg »

Fonction matrix_power - module scipy.sparse.linalg

Signature de la fonction matrix_power

def matrix_power(A, power) 

Description

help(scipy.sparse.linalg.matrix_power)

Raise a square matrix to the integer power, `power`.

For non-negative integers, ``A**power`` is computed using repeated
matrix multiplications. Negative integers are not supported. 

Parameters
----------
A : (M, M) square sparse array or matrix
    sparse array that will be raised to power `power`
power : int
    Exponent used to raise sparse array `A`

Returns
-------
A**power : (M, M) sparse array or matrix
    The output matrix will be the same shape as A, and will preserve
    the class of A, but the format of the output may be changed.

Notes
-----
This uses a recursive implementation of the matrix power. For computing
the matrix power using a reasonably large `power`, this may be less efficient
than computing the product directly, using A @ A @ ... @ A.
This is contingent upon the number of nonzero entries in the matrix. 

.. versionadded:: 1.12.0

Examples
--------
>>> from scipy import sparse
>>> A = sparse.csc_array([[0,1,0],[1,0,1],[0,1,0]])
>>> A.todense()
array([[0, 1, 0],
       [1, 0, 1],
       [0, 1, 0]])
>>> (A @ A).todense()
array([[1, 0, 1],
       [0, 2, 0],
       [1, 0, 1]])
>>> A2 = sparse.linalg.matrix_power(A, 2)
>>> A2.todense()
array([[1, 0, 1],
       [0, 2, 0],
       [1, 0, 1]])
>>> A4 = sparse.linalg.matrix_power(A, 4)
>>> A4.todense()
array([[2, 0, 2],
       [0, 4, 0],
       [2, 0, 2]])



Vous êtes un professionnel et vous avez besoin d'une formation ? Mise en oeuvre d'IHM
avec Qt et PySide6
Voir le programme détaillé