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 ? Coder avec une
Intelligence Artificielle
Voir le programme détaillé
Module « scipy.sparse »

Fonction spdiags - module scipy.sparse

Signature de la fonction spdiags

def spdiags(data, diags, m=None, n=None, format=None) 

Description

help(scipy.sparse.spdiags)

Return a sparse matrix from diagonals.

Parameters
----------
data : array_like
    Matrix diagonals stored row-wise
diags : sequence of int or an int
    Diagonals to set:

    * k = 0  the main diagonal
    * k > 0  the kth upper diagonal
    * k < 0  the kth lower diagonal
m, n : int, tuple, optional
    Shape of the result. If `n` is None and `m` is a given tuple,
    the shape is this tuple. If omitted, the matrix is square and
    its shape is len(data[0]).
format : str, optional
    Format of the result. By default (format=None) an appropriate sparse
    matrix format is returned. This choice is subject to change.

.. warning::

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

Notes
-----
This function can be replaced by an equivalent call to ``dia_matrix``
as::

    dia_matrix((data, diags), shape=(m, n)).asformat(format)

See Also
--------
diags_array : more convenient form of this function
diags : matrix version of diags_array
dia_matrix : the sparse DIAgonal format.

Examples
--------
>>> import numpy as np
>>> from scipy.sparse import spdiags
>>> data = np.array([[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]])
>>> diags = np.array([0, -1, 2])
>>> spdiags(data, diags, 4, 4).toarray()
array([[1, 0, 3, 0],
       [1, 2, 0, 4],
       [0, 2, 3, 0],
       [0, 0, 3, 4]])



Vous êtes un professionnel et vous avez besoin d'une formation ? Sensibilisation à
l'Intelligence Artificielle
Voir le programme détaillé