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 ? Calcul scientifique
avec Python
Voir le programme détaillé
Module « scipy.sparse »

Fonction identity - module scipy.sparse

Signature de la fonction identity

def identity(n, dtype='d', format=None) 

Description

help(scipy.sparse.identity)

Identity matrix in sparse format

Returns an identity matrix with shape (n,n) using a given
sparse format and dtype. This differs from `eye_array` in
that it has a square shape with ones only on the main diagonal.
It is thus the multiplicative identity. `eye_array` allows
rectangular shapes and the diagonal can be offset from the main one.

.. warning::

    This function returns a sparse matrix -- not a sparse array.
    You are encouraged to use ``eye_array`` to take advantage
    of the sparse array functionality.

Parameters
----------
n : int
    Shape of the identity matrix.
dtype : dtype, optional
    Data type of the matrix
format : str, optional
    Sparse format of the result, e.g., format="csr", etc.

Examples
--------
>>> import scipy as sp
>>> sp.sparse.identity(3).toarray()
array([[ 1.,  0.,  0.],
       [ 0.,  1.,  0.],
       [ 0.,  0.,  1.]])
>>> sp.sparse.identity(3, dtype='int8', format='dia')
<DIAgonal sparse matrix of dtype 'int8'
    with 3 stored elements (1 diagonals) and shape (3, 3)>
>>> sp.sparse.eye_array(3, dtype='int8', format='dia')
<DIAgonal sparse array of dtype 'int8'
    with 3 stored elements (1 diagonals) and shape (3, 3)>



Vous êtes un professionnel et vous avez besoin d'une formation ? Calcul scientifique
avec Python
Voir le programme détaillé