Skip to content

Gather and Scatter

Frank Seide edited this page Sep 22, 2016 · 6 revisions

BS.Sequences.Gather returns a subsequence of its input based on a mask

y = Gather(cond, x)

Gather returns the subsequence of those elements x[i] such that cond[i] is True.

Examples

ones  = ConstantTensor (1, 10)  #ones  = [1,1,1,1,1,1,1,1,1,1]
mask  = FoldL (Xor, 1, ones)    #mask  = [0,1,0,1,0,1,0,1,0,1]
range = FoldL (Plus, 0, ones)   #range = [1,2,3,4,5,6,7,8,9,10]
evens  = Gather(mask, range)   

should make evens contain the values [2,4,6,8,10]

Clone this wiki locally