The numpy.where() funkcija atgriež elementu indeksus ievades masīvā, kur ir izpildīts noteiktais nosacījums.
Sintakse : numpy.where(nosacījums[, x, y])
Parametri:
stāvoklis: Ja patiess, ienes x, pretējā gadījumā ienesīgums y.
x, y: Vērtības, no kurām izvēlēties. x, y un nosacījumam ir jābūt pārraidāmam noteiktā formā.
Atgriež:
ārā: [ndarray vai ndarrays korte] Ja ir norādīti gan x, gan y, izvades masīvā ir elementi x, kur nosacījums ir True, un elementi no y citur.pirmskaitļu programma javaJa ir dots tikai nosacījums, atgriež korteču condition.nonzero(), indeksus, kur nosacījums ir True.
Kods #1:
# Python program explaining> # where() function> > import> numpy as np> > np.where([[>True>,>False>], [>True>,>True>]],> >[[>1>,>2>], [>3>,>4>]], [[>5>,>6>], [>7>,>8>]])> |
>
>
virknes konvertēšana uz int java
Izvade:
array([[1, 6], [3, 4]])>
Kods #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])> |
>
>
python drukā līdz 2 zīmēm aiz komata
Izvade:
[[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])>