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 ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé
Module « scipy.sparse »

Fonction tril - module scipy.sparse

Signature de la fonction tril

def tril(A, k=0, format=None) 

Description

help(scipy.sparse.tril)

Return the lower triangular portion of a sparse array or matrix

Returns the elements on or below the k-th diagonal of A.
    - k = 0 corresponds to the main diagonal
    - k > 0 is above the main diagonal
    - k < 0 is below the main diagonal

Parameters
----------
A : dense or sparse array or matrix
    Matrix whose lower trianglar portion is desired.
k : integer : optional
    The top-most diagonal of the lower triangle.
format : string
    Sparse format of the result, e.g. format="csr", etc.

Returns
-------
L : sparse matrix
    Lower triangular portion of A in sparse format.

See Also
--------
triu : upper triangle in sparse format

Examples
--------
>>> from scipy.sparse import csr_array, tril
>>> A = csr_array([[1, 2, 0, 0, 3], [4, 5, 0, 6, 7], [0, 0, 8, 9, 0]],
...               dtype='int32')
>>> A.toarray()
array([[1, 2, 0, 0, 3],
       [4, 5, 0, 6, 7],
       [0, 0, 8, 9, 0]], dtype=int32)
>>> tril(A).toarray()
array([[1, 0, 0, 0, 0],
       [4, 5, 0, 0, 0],
       [0, 0, 8, 0, 0]], dtype=int32)
>>> tril(A).nnz
4
>>> tril(A, k=1).toarray()
array([[1, 2, 0, 0, 0],
       [4, 5, 0, 0, 0],
       [0, 0, 8, 9, 0]], dtype=int32)
>>> tril(A, k=-1).toarray()
array([[0, 0, 0, 0, 0],
       [4, 0, 0, 0, 0],
       [0, 0, 0, 0, 0]], dtype=int32)
>>> tril(A, format='csc')
<Compressed Sparse Column sparse array of dtype 'int32'
    with 4 stored elements and shape (3, 5)>



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