Fork me on GitHub

src/arraymancer/tensor/aggregate

Search:
Group by:
  Source Edit

Procs

func all[T](t: Tensor[T]): bool

Returns true if all of the items in the input tensor are true or non-zero

Input:

  • A tensor

Returns:

  • True if at least one element is not zero
  Source Edit
func any[T](t: Tensor[T]): bool

Returns true if any of the items in the input tensor is true or non-zero

Input:

  • A tensor

Returns:

  • True if at least one element is not zero
  Source Edit
proc argmax[T](arg: Tensor[T]; axis: int): Tensor[int] {.inline.}

Returns the index of the maximum along an axis

Input:

  • A tensor
  • An axis (int)

Returns:

  • A tensor of index of the maximums along this axis

Example: .. code:: nim let a = [0, 4, 7, 1, 9, 5, 3, 4, 1].toTensor assert argmax(a, 0) == [2, 1, 0].toTensor assert argmax(a, 1) == [2, 1, 1].toTensor

  Source Edit
proc argmax_max[T: SomeNumber](arg: Tensor[T]; axis: int): tuple[
    indices: Tensor[int], maxes: Tensor[T]] {.noinit.}

Returns (indices, maxes) along an axis

Input:

  • A tensor
  • An axis (int)

Returns:

  • A tuple of tensors (indices, maxes) along this axis

Example: .. code:: nim let a = [0, 4, 7, 1, 9, 5, 3, 4, 1].toTensor assert argmax(a, 0).indices == [2, 1, 0].toTensor assert argmax(a, 1).indices == [2, 1, 1].toTensor

  Source Edit
proc argmin[T](arg: Tensor[T]; axis: int): Tensor[int] {.inline.}

Returns the index of the minimum along an axis

Input:

  • A tensor
  • An axis (int)

Returns:

  • A tensor of index of the minimums along this axis

Example: .. code:: nim let a = [0, 4, 7, 1, 9, 5, 3, 4, 1].toTensor assert argmin(a, 0) == [2, 1, 0].toTensor assert argmin(a, 1) == [2, 1, 1].toTensor

  Source Edit
proc argmin_min[T: SomeNumber](arg: Tensor[T]; axis: int): tuple[
    indices: Tensor[int], mins: Tensor[T]] {.noinit.}

Returns (indices, mins) along an axis

Input:

  • A tensor
  • An axis (int)

Returns:

  • A tuple of tensors (indices, min) along this axis

Example: .. code:: nim let a = [0, 4, 7, 1, 9, 5, 3, 4, 1].toTensor assert argmin(a, 0).indices == [0, 0, 2].toTensor assert argmin(a, 1).indices == [0, 0, 2].toTensor

  Source Edit
proc cumprod[T](arg: Tensor[T]; axis: int = 0): Tensor[T]
Calculates the cumulative sum of a rank-n Tensor. Inputs:
  • t: a rank-n tensor to cumulatively sum
  • axis: int

Returns:

  • A tensor cumulatively summed at axis, that is, add each value to
  Source Edit
proc cumsum[T](arg: Tensor[T]; axis: int = 0): Tensor[T]
Calculates the cumulative sum of a rank-n Tensor. Inputs:
  • t: a rank-n tensor to cumulatively sum
  • axis: int

Returns:

  • A tensor cumulatively summed at axis, that is, add each value to
  Source Edit
proc diff_discrete[T](arg: Tensor[T]; n = 1; axis: int = -1): Tensor[T]

Calculate the n-th discrete difference along the given axis.

The first difference is given by out[i] = a[i+1] - a[i] along the given axis. Higher differences are calculated by using diff recursively.

Input:

  • A tensor
  • n: The number of times values are differenced. If zero, the input is returned as-is.
  • axis: The axis along which the difference is taken, default is the last axis.

Returns:

  • A tensor with the n-th discrete difference along the given axis. It's size along that axis will be reduced by one.
  • The code in this function is heavily based upon and equivalent

to numpy's diff() function.

  Source Edit
proc iqr[T](arg: Tensor[T]): float

Returns the interquartile range of the 1D tensor t.

The interquartile range (IQR) is the distance between the 25th and 75th percentile

  Source Edit
proc max[T](arg: Tensor[T]): T
Compute the max of all elements   Source Edit
proc max[T](arg: Tensor[T]; axis: int): Tensor[T] {.noinit.}
Compute the max along an axis   Source Edit
proc mean[T: Complex[float32] or Complex[float64]](arg: Tensor[T]): T {.inline.}
Compute the mean of all elements   Source Edit
proc mean[T: Complex[float32] or Complex[float64]](arg: Tensor[T]; axis: int): Tensor[
    T] {.noinit, inline.}
Compute the mean along an axis   Source Edit
proc mean[T: SomeFloat](arg: Tensor[T]): T {.inline.}
Compute the mean of all elements   Source Edit
proc mean[T: SomeFloat](arg: Tensor[T]; axis: int): Tensor[T] {.noinit, inline.}
Compute the mean along an axis   Source Edit
proc mean[T: SomeInteger](arg: Tensor[T]): T {.inline.}

Compute the mean of all elements

Warning âš : Since input is integer, output will also be integer (using integer division)

  Source Edit
proc mean[T: SomeInteger](arg: Tensor[T]; axis: int): Tensor[T] {.noinit, inline.}

Compute the mean along an axis

Warning âš : Since input is integer, output will also be integer (using integer division)

  Source Edit
proc median[T](arg: Tensor[T]; isSorted = false): float {.inline.}
Compute the median of all elements (same as arg.percentile(50))   Source Edit
proc min[T](arg: Tensor[T]): T
Compute the min of all elements   Source Edit
proc min[T](arg: Tensor[T]; axis: int): Tensor[T] {.noinit.}
Compute the min along an axis   Source Edit
proc nonzero[T](arg: Tensor[T]): Tensor[int]

Returns the indices, which are non zero as a Tensor[int].

The resulting tensor is 2 dimensional and has one element for each dimension in t. Each of those elements contains the indicies along the corresponding axis (element 0 == axis 0), which are non zero.

Input:

  • A tensor

Returns:

  • A 2D tensor with N elements, where N is the rank of t

Example: .. code:: nim let a = [3, 0, 0, 0, 4, 0, 5, 6, 0].toTensor() assert a.nonzero == [0, 1, 2, 2, 0, 1, 0, 1].toTensor # ^-- indices.. ^ ..for axis 0 # ∟-- indices for axis 1 # axis 0: 0, 1, 2, 2 refers to: # - 0 -> 3 in row 0 # - 1 -> 4 in row 1 # - 2 -> 5 in row 2 # - 2 -> 6 in row 2 # axis 1: 0, 1, 0, 1 refers to: # - 0 -> 3 in col 0 # - 1 -> 4 in col 1 # - 0 -> 5 in col 0 # - 1 -> 6 in col 1

  Source Edit
proc percentile[T](arg: Tensor[T]; p: int; isSorted = false): float

statistical percentile value of t, where p percentile value is between 0 and 100 inclusively, and p=0 gives the min value, p=100 gives the max value and p=50 gives the median value.

If the input percentile does not match an element of t exactly the result is the linear interpolation between the neighbors.

t does not need to be sorted, because percentile sorts a copy of the data itself. If isSorted is true however, no sorting is done.

  Source Edit
proc product[T](arg: Tensor[T]): T
Compute the product of all elements   Source Edit
proc product[T](arg: Tensor[T]; axis: int): Tensor[T] {.noinit.}
Compute the product along an axis   Source Edit
proc std[T: SomeFloat](arg: Tensor[T]): T {.inline.}
Compute the standard deviation of all elements The normalization is by the (n-1), like in the formal definition   Source Edit
proc std[T: SomeFloat](arg: Tensor[T]; axis: int): Tensor[T] {.noinit, inline.}
Compute the standard deviation of all elements The normalization is by the (n-1), like in the formal definition   Source Edit
proc sum[T](arg: Tensor[T]): T
Compute the sum of all elements   Source Edit
proc sum[T](arg: Tensor[T]; axis: int): Tensor[T] {.noinit.}
Compute the sum of all elements along an axis   Source Edit
proc unwrap_period[T: SomeNumber](t: Tensor[T]; discont: T = -1; axis = -1;
                                  period: T = default(T)): Tensor[T] {.noinit.}
  Source Edit
proc variance[T: SomeFloat](arg: Tensor[T]): T
Compute the sample variance of all elements The normalization is by (n-1), also known as Bessel's correction, which partially correct the bias of estimating a population variance from a sample of this population.   Source Edit
proc variance[T: SomeFloat](arg: Tensor[T]; axis: int): Tensor[T] {.noinit.}
Compute the variance of all elements The normalization is by the (n-1), like in the formal definition   Source Edit
Arraymancer Technical reference Tutorial Spellbook (How-To's) Under the hood