The numpy.where() Funkce vrací indexy prvků ve vstupním poli, kde je daná podmínka splněna.
Syntaxe: numpy.where(podmínka[, x, y])
Parametry:
podmínka: Když je pravda, výnos x, jinak výnos y.
x, y: Hodnoty, ze kterých si vybrat. x, y a podmínka musí být přenositelné do nějakého tvaru.
Vrácení:
ven : [ndarray nebo n-tice ndarrays] Pokud jsou zadány x i y, výstupní pole obsahuje prvky x, kde je podmínka True, a prvky z y jinde.Pokud je zadána pouze podmínka, vraťte n-tici condition.nonzero(), indexy, kde je podmínka True.
Kód #1:
mylivecricket v živém kriketu
# Python program explaining> # where() function> > import> numpy as np> > np.where([[> True> ,> False> ], [> True> ,> True> ]],> > [[> 1> ,> 2> ], [> 3> ,> 4> ]], [[> 5> ,> 6> ], [> 7> ,> 8> ]])> |
>
>
Výstup :
array([[1, 6], [3, 4]])>
Kód #2:
# Python program explaining> # where() function> > import> numpy as np> > # a is an array of integers.> a> => np.array([[> 1> ,> 2> ,> 3> ], [> 4> ,> 5> ,> 6> ]])> > print> (a)> > print> (> 'Indices of elements <4'> )> > b> => np.where(a<> 4> )> print> (b)> > print> (> 'Elements which are <4'> )> print> (a[b])> |
>
>
java mvc
Výstup :
[[1 2 3] [4 5 6]] Indices of elements <4 (array([0, 0, 0], dtype=int64), array([0, 1, 2], dtype=int64)) Elements which are <4 array([1, 2, 3])>