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 ? Programmation Python
Les compléments
Voir le programme détaillé
Module « scipy.sparse »

Fonction kron - module scipy.sparse

Signature de la fonction kron

def kron(A, B, format=None) 

Description

help(scipy.sparse.kron)

kronecker product of sparse matrices A and B

Parameters
----------
A : sparse or dense matrix
    first matrix of the product
B : sparse or dense matrix
    second matrix of the product
format : str, optional (default: 'bsr' or 'coo')
    format of the result (e.g. "csr")
    If None, choose 'bsr' for relatively dense array and 'coo' for others

Returns
-------
kronecker product in a sparse format.
Returns a sparse matrix unless either A or B is a
sparse array in which case returns a sparse array.

Examples
--------
>>> import numpy as np
>>> import scipy as sp
>>> A = sp.sparse.csr_array(np.array([[0, 2], [5, 0]]))
>>> B = sp.sparse.csr_array(np.array([[1, 2], [3, 4]]))
>>> sp.sparse.kron(A, B).toarray()
array([[ 0,  0,  2,  4],
       [ 0,  0,  6,  8],
       [ 5, 10,  0,  0],
       [15, 20,  0,  0]])

>>> sp.sparse.kron(A, [[1, 2], [3, 4]]).toarray()
array([[ 0,  0,  2,  4],
       [ 0,  0,  6,  8],
       [ 5, 10,  0,  0],
       [15, 20,  0,  0]])



Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les compléments
Voir le programme détaillé