groups#

swordfish.function.groups()#

For each unique value in X, return the indices of all elements that hold the value.

  • If mode = “dict”, return a dictionary.

  • If mode = “table”, return a table with 2 columns, key and index. Each cell in the column index is an array vector.

Parameters:
  • X (Constant) – A vector.

  • mode (Constant, optional) –

    Indicates the data form returned by the function. It can be:

    • ”dict” (default): return a dictionary. The key of the dictionary stores the unique value in X; the value is a vector that stores the indices of all elements that hold the value.

    • ”table”: return a table with 2 columns, “key” and “index”, storing the unique value in X and the corresponding indices.

    • ”vector”: return an array vector. The elements are the indices of each unique value in X, sorted in ascending order.

    • ”tuple”: return a tuple. The elements are stored the same as mode=”vector”.