Skip to content

array

Functions

from

pine
array.from(T values) → array<T>

This function creates a new array containing the provided values.

Parameters

NameTypeDefaultDescription
valuesTVariable number of elements to include in the array.

Returns: array<T>


new

pine
array.new(int size = 0, T initial_value = na) → const array<T>

This function creates a new empty array of type T.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valueTnaThe initial value for all elements.

Returns: const array<T>


new_bool

pine
array.new_bool(int size = 0, bool initial_value = false) → const array<bool>

This function creates a new empty array of type bool.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valueboolfalseThe initial value for all elements.

Returns: const array<bool>


new_box

pine
array.new_box(int size = 0, box initial_value = na) → const array<box>

This function creates a new empty array of type box.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valueboxnaThe initial value for all elements.

Returns: const array<box>


new_color

pine
array.new_color(int size = 0, color initial_value = na) → const array<color>

This function creates a new empty array of type color.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valuecolornaThe initial value for all elements.

Returns: const array<color>


new_float

pine
array.new_float(int size = 0, float initial_value = na) → const array<float>

This function creates a new empty array of type float.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valuefloatnaThe initial value for all elements.

Returns: const array<float>


new_int

pine
array.new_int(int size = 0, int initial_value = na) → const array<int>

This function creates a new empty array of type int.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valueintnaThe initial value for all elements.

Returns: const array<int>


new_label

pine
array.new_label(int size = 0, label initial_value = na) → const array<label>

This function creates a new empty array of type label.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valuelabelnaThe initial value for all elements.

Returns: const array<label>


new_line

pine
array.new_line(int size = 0, line initial_value = na) → const array<line>

This function creates a new empty array of type line.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valuelinenaThe initial value for all elements.

Returns: const array<line>


new_linefill

pine
array.new_linefill(
    int size = 0,
    linefill initial_value = na
  ) → const array<linefill>

This function creates a new empty array of type linefill.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valuelinefillnaThe initial value for all elements.

Returns: const array<linefill>


new_string

pine
array.new_string(int size = 0, string initial_value = na) → const array<string>

This function creates a new empty array of type string.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valuestringnaThe initial value for all elements.

Returns: const array<string>


new_table

pine
array.new_table(int size = 0, table initial_value = na) → const array<table>

This function creates a new empty array of type table.

Parameters

NameTypeDefaultDescription
sizeint0The initial size of the array.
initial_valuetablenaThe initial value for all elements.

Returns: const array<table>

Methods

abs

This function returns a new array containing the absolute values of the elements of the input array.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integer elements.

Returns: array<int>

Returns absolute values.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of float elements.

Returns: array<float>


avg

This function returns the average of the elements in the input array.

Parameters

NameTypeDefaultDescription
arrayseries array<int>The input array of integer elements.

Returns: float

Returns the average.

Parameters

NameTypeDefaultDescription
arrayseries array<float>The input array of float elements.

Returns: float


This function performs a binary search for the specified value in the given sorted array and returns the index of the value if found, or -1 if not found.

Parameters

NameTypeDefaultDescription
arrayarray<int>The sorted array of integers to search.
valueintThe value to search for.

Returns: int — The index of the value, or -1 if not found. The array must be sorted in ascending order.

Binary search.

Parameters

NameTypeDefaultDescription
arrayarray<float>The sorted array of floats to search.
valuefloatThe value to search for.

Returns: int


binary_search_leftmost

This function returns the index of the value if it is found.

When the value is not found, the function returns the index of the next smallest element to the left of where the value would lie if it was in the array. The array to search must be sorted in ascending order.

Parameters

NameTypeDefaultDescription
arrayarray<int>The sorted array of integers to search.
valueintThe value to search for.

Returns: int

Binary search leftmost.

Parameters

NameTypeDefaultDescription
arrayarray<float>The sorted array of floats to search.
valuefloatThe value to search for.

Returns: int


binary_search_rightmost

This function returns the index of the value if it is found.

When the value is not found, the function returns the index of the element to the right of where the value would lie if it was in the array. The array must be sorted in ascending order.

Parameters

NameTypeDefaultDescription
arrayarray<int>The sorted array of integers to search.
valueintThe value to search for.

Returns: int

Binary search rightmost.

Parameters

NameTypeDefaultDescription
arrayarray<float>The sorted array of floats to search.
valuefloatThe value to search for.

Returns: int


clear

pine
array.clear(series array<T> array)

This function clears all elements from the given array.

Parameters

NameTypeDefaultDescription
arrayseries array<T>The array to clear.

concat

pine
array.concat(array<T> array1, array<T> array2) → array<T>

This function concatenates two arrays array1 and array2 of the same type T and returns a new array containing all elements from both arrays.

Parameters

NameTypeDefaultDescription
array1array<T>The first array to concatenate.
array2array<T>The second array to concatenate.

Returns: array<T>


copy

pine
array.copy(array<T> array) → array<T>

This function creates a copy of the given array and returns the new array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to copy.

Returns: array<T>


covariance

This function calculates the covariance between two arrays array1 and array2 of the same type T.

The biased parameter determines whether to use biased or unbiased estimation.

Parameters

NameTypeDefaultDescription
array1array<float>The first input array.
array2array<float>The second input array.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Covariance.

Parameters

NameTypeDefaultDescription
array1array<int>The first input array.
array2array<int>The second input array.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Covariance.

Parameters

NameTypeDefaultDescription
array1array<int>The first input array.
array2array<float>The second input array.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Covariance.

Parameters

NameTypeDefaultDescription
array1array<float>The first input array.
array2array<int>The second input array.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float


every

This function checks if every element in the given boolean array is true.

It returns true if all elements are true, and false otherwise.

Parameters

NameTypeDefaultDescription
arrayarray<bool>The array to check.

Returns: bool

Checks if every element is true.

Parameters

NameTypeDefaultDescription
arrayarray<int>The array to check.

Returns: bool

Checks if every element is true.

Parameters

NameTypeDefaultDescription
arrayarray<float>The array to check.

Returns: bool


fill

pine
array.fill(array<T> array, T value, int index_from = 0, int index_to = na)

This function fills the elements of the given array with the specified value from index_from to index_to.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to fill.
valueTThe value to fill with.
index_fromint0The starting index (inclusive).
index_tointnaThe ending index (exclusive). When na, denotes end of array.

first

pine
array.first(array<T> array) → T

This function returns the first element of the given array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to retrieve the first element from.

Returns: T


get

pine
array.get(array<T> array, int index) → T

This function returns the element at the specified index from the given array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to retrieve the element from.
indexintThe index of the element to retrieve.

Returns: T


includes

pine
array.includes(array<T> array, T value) → bool

This function checks if the given array includes the specified value.

It returns true if the value is found in the array, and false otherwise.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to search.
valueTThe value to search for.

Returns: bool


indexof

pine
array.indexof(array<T> array, T value) → int

This function returns the index of the first occurrence of the specified value in the given array.

If the value is not found, it returns -1.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to search.
valueTThe value to search for.

Returns: int — The zero-based index of the first occurrence, or -1 if not found.


insert

pine
array.insert(array<T> array, int index, T value)

This function inserts the specified value at the given index in the array, shifting subsequent elements to the right.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to modify.
indexintThe index at which to insert the value.
valueTThe value to insert.

join

This function joins the elements of the given array into a single string, with each element separated by the specified separator.

Parameters

NameTypeDefaultDescription
arrayarray<int>The array of integers to join.
separatorstringThe separator string to place between elements.

Returns: string

Joins array elements into string.

Parameters

NameTypeDefaultDescription
arrayarray<float>The array of floats to join.
separatorstringThe separator string to place between elements.

Returns: string

Joins array elements into string.

Parameters

NameTypeDefaultDescription
arrayarray<string>The array of strings to join.
separatorstringThe separator string to place between elements.

Returns: string


last

pine
array.last(array<T> array) → T

This function returns the last element of the given array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to retrieve the last element from.

Returns: T


lastindexof

pine
array.lastindexof(array<T> array, T value) → int

This function returns the index of the last occurrence of the specified value in the given array.

If the value is not found, it returns -1.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to search.
valueTThe value to search for.

Returns: int — The zero-based index of the last occurrence, or -1 if not found.


max

This function returns the nth maximum value from the given array.

The nth parameter specifies which maximum to return (0 for the largest, 1 for the second largest, etc.).

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.
nthint0Which maximum to return (0 for the largest, 1 for the second largest, etc.).

Returns: int

Returns the nth maximum value.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.
nthint0Which maximum to return (0 for the largest, 1 for the second largest, etc.).

Returns: float


median

This function returns the median value of the elements in the given array.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.

Returns: float

Returns the median.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.

Returns: float


min

This function returns the nth minimum value from the given array.

The nth parameter specifies which minimum to return (0 for the smallest, 1 for the second smallest, etc.).

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.
nthint0Which minimum to return (0 for the smallest, 1 for the second smallest, etc.).

Returns: int

Returns the nth minimum value.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.
nthint0Which minimum to return (0 for the smallest, 1 for the second smallest, etc.).

Returns: float


mode

The function returns the mode of an array's elements.

If there are several values with the same frequency, it returns the smallest value.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.

Returns: int — The most frequently occurring value, or the smallest among tied values.

Returns the mode.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.

Returns: float


percentile_linear_interpolation

This function returns the value at the specified percentile from the given array using linear interpolation.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.
percentagefloatThe percentile value (0-100).

Returns: float

Returns value at percentile with linear interpolation.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.
percentagefloatThe percentile value (0-100).

Returns: float


percentile_nearest_rank

This function returns the value at the specified percentile from the given array using the nearest-rank method.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.
percentagefloatThe percentile value (0-100).

Returns: float

Returns value at percentile with nearest-rank.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.
percentagefloatThe percentile value (0-100).

Returns: float


percentrank

This function returns the percentile rank of the element at the specified index in the given array.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.
indexintThe index of the element.

Returns: float — A value between 0 and 100 indicating the percentage of elements that are less than or equal to the element at index.

Returns percentile rank.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.
indexintThe index of the element.

Returns: float — A value between 0 and 100 indicating the percentage of elements that are less than or equal to the element at index.


pop

pine
array.pop(array<T> array) → T

This function removes and returns the last element from the given array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array from which to pop an element.

Returns: T


push

pine
array.push(array<T> array, T value)

This function appends the given value to the end of the array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to which the value will be appended.
valueTThe value to append to the array.

range

This function returns the range (difference between the maximum and minimum values) of the elements in the given array.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.

Returns: int

Returns the range.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.

Returns: float


remove

pine
array.remove(array<T> array, int index) → T

This function removes the element at the specified index from the given array and returns the removed element.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to modify.
indexintThe index of the element to remove.

Returns: T


reverse

pine
array.reverse(array<T> array)

This function reverses the order of elements in the given array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to reverse.

set

pine
array.set(array<T> array, int index, T value)

Sets the element at the specified index in the array to the provided value.

If the index is positive, the function counts from the beginning of the array (0-based), and if the index is negative, it counts from the end of the array (-1 being the last element). For example, for an array that contains [10, 20, 30], all of the following indexes are valid: 0, 1, 2, -1, -2, -3.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to modify.
indexintThe index of the element (supports negative indexing).
valueTThe value to set at the specified index.

shift

pine
array.shift(array<T> array) → T

This function removes and returns the first element from the given array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array from which to shift an element.

Returns: T


size

pine
array.size(array<T> array) → int

This function returns the size (number of elements) of the given array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array whose size is to be determined.

Returns: int


slice

pine
array.slice(array<T> array, int index_from = 0, int index_to = na) → array<T>

This function creates a new array that is a slice of the given array, starting from index_from to index_to.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to slice.
index_fromint0The starting index (inclusive).
index_tointnaThe ending index (exclusive). When na, denotes end of array.

Returns: array<T>


some

This function checks if at least one element in the given boolean array is true.

It returns true if any element is true, and false otherwise.

Parameters

NameTypeDefaultDescription
arrayarray<bool>The array to check.

Returns: bool

Checks if at least one element is true.

Parameters

NameTypeDefaultDescription
arrayarray<int>The array to check.

Returns: bool

Checks if at least one element is true.

Parameters

NameTypeDefaultDescription
arrayarray<float>The array to check.

Returns: bool


sort

This function sorts the elements of the given array in ascending or descending order.

Parameters

NameTypeDefaultDescription
arrayarray<int>The array of integers to sort.
orderanyorder.ascendingThe sort order.

Sorts array elements.

Parameters

NameTypeDefaultDescription
arrayarray<float>The array of floats to sort.
orderanyorder.ascendingThe sort order.

Sorts array elements.

Parameters

NameTypeDefaultDescription
arrayarray<string>The array of strings to sort.
orderanyorder.ascendingThe sort order.

sort_indices

This function returns an array of indices that would sort the given array.

Parameters

NameTypeDefaultDescription
arrayarray<int>The array of integers to analyze.
orderanyorder.ascendingThe sort order.

Returns: array<int> — An array of original indices rearranged so that array.get(result.get(i)) yields the i-th sorted element.

Returns sort indices.

Parameters

NameTypeDefaultDescription
arrayarray<float>The array of floats to analyze.
orderanyorder.ascendingThe sort order.

Returns: array<int>

Returns sort indices.

Parameters

NameTypeDefaultDescription
arrayarray<string>The array of strings to analyze.
orderanyorder.ascendingThe sort order.

Returns: array<int>


standardize

This function standardizes the elements of the given array by subtracting the mean and dividing by the standard deviation.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.

Returns: array<float> — A new array where each element is (value - mean) / stdev (z-scores).

Standardizes array elements.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.

Returns: array<float>


stdev

This function calculates the standard deviation of the elements in the given array.

The biased parameter determines whether to use biased or unbiased estimation.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Returns standard deviation.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float


sum

This function calculates the sum of the elements in the given array.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.

Returns: int

Returns the sum.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.

Returns: float


unshift

pine
array.unshift(array<T> array, T value)

This function adds the specified value to the beginning of the given array.

Parameters

NameTypeDefaultDescription
arrayarray<T>The array to modify.
valueTThe value to add to the beginning.

variance

This function calculates the variance of the elements in the given array.

The biased parameter determines whether to use biased or unbiased estimation.

Parameters

NameTypeDefaultDescription
arrayarray<int>The input array of integers.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Returns variance.

Parameters

NameTypeDefaultDescription
arrayarray<float>The input array of floats.
biasedanytrueIf true, the function uses biased estimation (dividing by n); if false, it uses unbiased estimation (dividing by n-1).

Returns: float

Released under the MIT License.