Array class index_of interface¶
This page explains the Array
class index_of
method interface.
What interface is this?¶
The index_of
method returns the specified value’s index in the array.
Basic usage¶
The index_of
method requires the value
argument and returns the found value’s index in the array.
import apysc as ap
ap.Stage()
arr: ap.Array[int] = ap.Array([1, 3, 5])
index: ap.Int = arr.index_of(value=3)
assert index == 1
If there is no found value, the return index becomes -1
.
import apysc as ap
ap.Stage()
arr: ap.Array[int] = ap.Array([1, 3, 5])
index: ap.Int = arr.index_of(value=2)
assert index == -1
index_of API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface signature] index_of(self, value: ~_ArrValue) -> apysc._type.int.Int
[Interface summary]
Search specified value’s index and return it.
[Parameters]
value
: *Any value to search.
[Returns]
index
: IntFound position of index. If this array does not contain a value, this interface returns -1.
[Examples]
>>> import apysc as ap
>>> _ = ap.Stage()
>>> arr: ap.Array = ap.Array([1, 3, 5])
>>> arr.index_of(3)
Int(1)