github.com/qiaogw/arrgo@v0.0.8/arraysetops.go (about)

     1  package arrgo
     2  
     3  import (
     4      "sort"
     5  )
     6  
     7  //Find the unique elements of an array.
     8  //
     9  //Returns the sorted unique elements of an array. There are three optional
    10  //outputs in addition to the unique elements: the indices of the input array
    11  //that give the unique values, the indices of the unique array that
    12  //reconstruct the input array, and the number of times each unique value
    13  //comes up in the input array.
    14  //
    15  //Parameters
    16  //----------
    17  //ar : array_like
    18  //Input array. This will be flattened if it is not already 1-D.
    19  //return_index : bool, optional
    20  //If True, also return the indices of `ar` that result in the unique
    21  //array.
    22  //return_inverse : bool, optional
    23  //If True, also return the indices of the unique array that can be used
    24  //to reconstruct `ar`.
    25  //return_counts : bool, optional
    26  //If True, also return the number of times each unique value comes up
    27  //in `ar`.
    28  //
    29  //.. versionadded:: 1.9.0
    30  //
    31  //Returns
    32  //-------
    33  //unique : ndarray
    34  //The sorted unique values.
    35  //unique_indices : ndarray, optional
    36  //The indices of the first occurrences of the unique values in the
    37  //(flattened) original array. Only provided if `return_index` is True.
    38  //unique_inverse : ndarray, optional
    39  //The indices to reconstruct the (flattened) original array from the
    40  //unique array. Only provided if `return_inverse` is True.
    41  //unique_counts : ndarray, optional
    42  //The number of times each of the unique values comes up in the
    43  //original array. Only provided if `return_counts` is True.
    44  func Unique(a *Arrf) *Arrf {
    45      uniques := make([]float64, 0, a.Length())
    46      for _, v := range a.Values() {
    47          if !ContainsFloat64(uniques, v) {
    48              uniques = append(uniques, v)
    49          }
    50      }
    51      sort.Float64s(uniques)
    52      return Array(uniques)
    53  }
    54  
    55  //Find the intersection of two arrays.
    56  //    Return the sorted, unique values that are in both of the input arrays.
    57  //    Parameters
    58  //    ----------
    59  //    ar1, ar2 : array_like
    60  //        Input arrays.
    61  //    assume_unique : bool
    62  //        If True, the input arrays are both assumed to be unique, which
    63  //        can speed up the calculation.  Default is False.
    64  //    Returns
    65  //    -------
    66  //    intersect1d : ndarray
    67  //        Sorted 1D array of common and unique elements.
    68  //func Intersect1d(a, b *Arrf) *Arrf {
    69  //	ar1 := Unique(a)
    70  //	ar2 := Unique(b)
    71  //
    72  //}