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 eye - module scipy.sparse

Signature de la fonction eye

def eye(m, n=None, k=0, dtype=<class 'float'>, format=None) 

Description

help(scipy.sparse.eye)

Sparse matrix with ones on diagonal

Returns a sparse matrix (m x n) where the kth diagonal
is all ones and everything else is zeros.

Parameters
----------
m : int
    Number of rows in the matrix.
n : int, optional
    Number of columns. Default: `m`.
k : int, optional
    Diagonal to place ones on. Default: 0 (main diagonal).
dtype : dtype, optional
    Data type of the matrix.
format : str, optional
    Sparse format of the result, e.g., format="csr", etc.

.. 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.

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



Vous êtes un professionnel et vous avez besoin d'une formation ? RAG (Retrieval-Augmented Generation)
et Fine Tuning d'un LLM
Voir le programme détaillé