segment#

swordfish.function.segment()#

Divide a vector into groups. Each group is composed of identical values next to each other. For example, [1,1,2,2,1,1,1] is divided into 3 groups: [1,1], [2,2] and [1,1,1].

Parameters:
  • X (Constant) – A vector.

  • segmentOffset (Constant, optional) – A Boolean value, by default DFLT.

Returns:

Return a vector of the same length as X.

  • If segmentOffset=true, each element of the result is the index(in X) of the first element in each group.

  • If segmentOffset=false, each element of the result is its group number. Group numbers start from 0.

Return type:

Constant