Array class¶
This page explains the Array
class.
Before reading on, maybe it is helpful to read the following page:
What is the Array?¶
The Array
class is the apysc array class. It behaves like the Python built-in list
value.
Constructor method¶
The Array
class constructor method requires iterable objects, like the list
, tuple
, range
, or Array
value.
import apysc as ap
arr_from_list: ap.Array = ap.Array([1, 2, 3])
assert arr_from_list == [1, 2, 3]
arr_from_tuple: ap.Array = ap.Array((4, 5, 6))
assert arr_from_tuple == [4, 5, 6]
other_arr: ap.Array = ap.Array([7, 8, 9])
arr_from_arr: ap.Array = ap.Array(other_arr)
assert arr_from_arr == [7, 8, 9]
Generic type annotation¶
If the Array
values types are unique, you can set the generic type to an Array
value. This annotation may be helpful when you use it on the IDE (for type checkers).
import apysc as ap
arr: ap.Array[int] = ap.Array([1, 2])
int_val: int = arr.pop()
assert isinstance(int_val, int)
See also¶
Array class constructor 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] __init__(self, value: Union[List[~T], tuple, range, ForwardRef('Array')], *, variable_name_suffix: str = '', skip_init_substitution_expression_appending: bool = False) -> None
[Interface summary]
Array class for the apysc library.
[Parameters]
value
: Array or list or tuple or rangeInitial array value.
variable_name_suffix
: str, default ‘’A JavaScript variable name suffix string. This setting is sometimes useful for JavaScript’s debugging.
skip_init_substitution_expression_appending
: bool, default FalseA boolean indicates whether to skip an initial substitution expression or not. This class uses this option internally.
[Examples]
>>> import apysc as ap
>>> arr: ap.Array = ap.Array([1, 2, 3])
>>> arr
Array([1, 2, 3])
>>> arr[0]
1
>>> arr[1]
2
>>> arr = ap.Array((4, 5, 6))
>>> arr
Array([4, 5, 6])
>>> arr = ap.Array(range(3))
>>> arr
Array([0, 1, 2])
[References]
value property API¶
Note: the document build script generates and updates this API document section automatically. Maybe this section is duplicated compared with previous sections.
[Interface summary]
Get a current array value.
[Returns]
value
: listCurrent array value.
[Examples]
>>> import apysc as ap
>>> arr: ap.Array = ap.Array([1, 2, 3])
>>> arr.value = [4, 5, 6]
>>> arr.value
[4, 5, 6]
[References]