arK()
What does arK() do?
arK() creates an array based on the values inside of it, repeated K times. For example, ar1(1, 2, 3, 4) makes the array [1, 2, 3, 4].
from ArrayExpressions import arrex
lst = [1, 2, 3, 4, 5]
output = arrex.evaluate(lst, "x == arL(I + 1)")
print(output) # True
This code showcases a useful way to use arK(). By supplying arK() with I, a list will be created in the form of [0, 1, ... K - 1]. By putting L for K, a list of the same length as x is created. So arL(I + 1), in the above example, creates a list of length 5 with elements of 1, 2, 3, 4, and 5. For a simpler example, look below.
Other Important Information:
Input | Comma separated values (if 1 value, no comma needed) |
---|---|
Does it create a new scope? | No |
Output | An array containing every element repeated K times |
K | Any number, optional |
I | The index of each element in the new array |
Example | ar4(1, 2) |
Example Explanation | This creates an array [1, 2, 1, 2, 1, 2, 1, 2] |