scipy.sparse.

get_index_dtype#

scipy.sparse.get_index_dtype(arrays=(), maxval=None, check_contents=False)[Quelle]#

Bestimmen Sie basierend auf den Eingabe- (Integer-)Arrays a einen geeigneten Datentyp für Indizes, der die Daten in den Arrays aufnehmen kann.

Parameter:
arraystuple of array_like

Eingabe-Arrays, deren Typen/Inhalte geprüft werden sollen

maxvalfloat, optional

Maximal benötigter Wert

check_contentsbool, optional

Ob die Werte in den Arrays und nicht nur ihre Typen geprüft werden sollen. Standard: False (nur die Typen prüfen)

Rückgabe:
dtypedtype

Geeigneter Datentyp für Indizes (int32 oder int64)

Beispiele

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