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].

参数:
  • X (Constant) -- A vector.

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

返回:

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.

返回类型:

Constant