tf.ragged.boolean_mask

Applies a boolean mask to data without flattening the mask dimensions.

Used in the notebooks

Used in the guide

Returns a potentially ragged tensor that is formed by retaining the elements in data where the corresponding value in mask is True.

  • output[a1...aA, i, b1...bB] = data[a1...aA, j, b1...bB]

    Where j is the ith True entry of mask[a1...aA].

Note that output preserves the mask dimensions a1...aA; this differs from tf.boolean_mask, which flattens those dimensions.

data A potentially ragged tensor.
mask A potentially ragged boolean tensor. mask's shape must be a prefix of data's shape. rank(mask) must be known statically.
name A name prefix for the returned tensor (optional).

A potentially ragged tensor that is formed by retaining the elements in data where the corresponding value in mask is True.

  • rank(output) = rank(data).
  • output.ragged_rank = max(data.ragged_rank, rank(mask) - 1).

ValueError if rank(mask) is not known statically; or if mask.shape is not a prefix of d