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

Fonction get_index_dtype - module scipy.sparse

Signature de la fonction get_index_dtype

def get_index_dtype(arrays=(), maxval=None, check_contents=False) 

Description

help(scipy.sparse.get_index_dtype)

Based on input (integer) arrays `a`, determine a suitable index data
type that can hold the data in the arrays.

Parameters
----------
arrays : tuple of array_like
    Input arrays whose types/contents to check
maxval : float, optional
    Maximum value needed
check_contents : bool, optional
    Whether to check the values in the arrays and not just their types.
    Default: False (check only the types)

Returns
-------
dtype : dtype
    Suitable index data type (int32 or int64)

Examples
--------
>>> import numpy as np
>>> from scipy import sparse
>>> # select index dtype based on shape
>>> shape = (3, 3)
>>> idx_dtype = sparse.get_index_dtype(maxval=max(shape))
>>> data = [1.1, 3.0, 1.5]
>>> indices = np.array([0, 1, 0], dtype=idx_dtype)
>>> indptr = np.array([0, 2, 3, 3], dtype=idx_dtype)
>>> A = sparse.csr_array((data, indices, indptr), shape=shape)
>>> A.indptr.dtype
dtype('int32')

>>> # select based on larger of existing arrays and shape
>>> shape = (3, 3)
>>> idx_dtype = sparse.get_index_dtype(A.indptr, maxval=max(shape))
>>> idx_dtype
<class 'numpy.int32'>


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