Procs
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 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 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]; axis: int): Tensor[T] {.noinit, inline.}
- Compute the mean 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 unwrap_period[T: SomeNumber](t: Tensor[T]; discont: T = -1; axis = -1; period: T = default(T)): Tensor[T] {.noinit.}
- Source Edit