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 fondamentaux
Voir le programme détaillé
Module « scipy.sparse »

Classe « dok_matrix »

Informations générales

Héritage

builtins.object
    builtins.dict
builtins.object
    IndexMixin
builtins.object
    _spbase
        _dok_base
    builtins.object
        spmatrix
            dok_matrix

Définition

class dok_matrix(spmatrix, _dok_base):

help(dok_matrix)

Dictionary Of Keys based sparse matrix.

This is an efficient structure for constructing sparse
matrices incrementally.

This can be instantiated in several ways:
    dok_matrix(D)
        where D is a 2-D ndarray

    dok_matrix(S)
        with another sparse array or matrix S (equivalent to S.todok())

    dok_matrix((M,N), [dtype])
        create the matrix with initial shape (M,N)
        dtype is optional, defaulting to dtype='d'

Attributes
----------
dtype : dtype
    Data type of the matrix
shape : 2-tuple
    Shape of the matrix
ndim : int
    Number of dimensions (this is always 2)
nnz
    Number of nonzero elements
size
T

Notes
-----

Sparse matrices can be used in arithmetic operations: they support
addition, subtraction, multiplication, division, and matrix power.

- Allows for efficient O(1) access of individual elements.
- Duplicates are not allowed.
- Can be efficiently converted to a coo_matrix once constructed.

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import dok_matrix
>>> S = dok_matrix((5, 5), dtype=np.float32)
>>> for i in range(5):
...     for j in range(5):
...         S[i, j] = i + j    # Update element

Constructeur(s)

Signature du constructeur Description
__init__(self, arg1, shape=None, dtype=None, copy=False, *, maxprint=None)

Liste des propriétés

Nom de la propriétéDescription
formatFormat string for matrix. [extrait de format.__doc__]
imag
ndim
nnzNumber of stored values, including explicit zeros. [extrait de nnz.__doc__]
real
shapeGet shape of a sparse matrix. [extrait de shape.__doc__]
sizeNumber of stored values. [extrait de size.__doc__]
TTranspose. [extrait de T.__doc__]

Liste des opérateurs

Signature de l'opérateur Description
__ior__(self, other)
__or__(self, other)
__ror__(self, other)

Opérateurs hérités de la classe _dok_base

__add__, __contains__, __delitem__, __imul__, __itruediv__, __neg__, __radd__, __truediv__

Opérateurs hérités de la classe dict

__eq__, __ge__, __getitem__, __gt__, __le__, __lt__, __ne__, __setitem__

Opérateurs hérités de la classe IndexMixin

__getitem__, __setitem__

Opérateurs hérités de la classe _spbase

__eq__, __ge__, __gt__, __iadd__, __isub__, __le__, __lt__, __matmul__, __mul__, __ne__, __pow__, __rmul__, __rsub__, __rtruediv__, __sub__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__class_getitem__(object) See PEP 585 [extrait de __class_getitem__.__doc__]
__reversed__(self)
get_shape(self) Get shape of a sparse matrix. [extrait de get_shape.__doc__]
set_shape(self, shape)

Méthodes héritées de la classe _dok_base

__init_subclass__, __len__, __reduce__, __subclasshook__, astype, clear, conjtransp, copy, count_nonzero, diagonal, fromkeys, get, items, keys, pop, popitem, resize, setdefault, tocoo, tocsc, todok, transpose, update, values

Méthodes héritées de la classe dict

__getattribute__, __iter__, __repr__, __sizeof__

Méthodes héritées de la classe _spbase

__abs__, __bool__, __div__, __idiv__, __iter__, __nonzero__, __rdiv__, __repr__, __rmatmul__, __round__, __str__, asformat, conj, conjugate, dot, maximum, mean, minimum, multiply, nonzero, power, reshape, setdiag, sum, toarray, tobsr, tocsr, todense, todia, tolil, trace

Méthodes héritées de la classe spmatrix

asfptype, getcol, getformat, getH, getmaxprint, getnnz, getrow

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getattribute__, __getstate__, __hash__, __reduce_ex__, __setattr__, __sizeof__

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é