Skip to content

Add tf.booleanMask() op. #380

@hiddentn

Description

@hiddentn

TensorFlow.js version

0.11.1

Browser version

68

Describe the problem or feature request

i am currently trying to grap a few values from a tensor using Tensor.data() witch takes a lot of time given a large tensor.

const mask=tf.where(......)
const all_indices = tf.range(1,N+1,1"int32");
  //starting at 1 to prevent 0x0
const indices = mask.toInt().mul(all_indices)
const indicesArr = Array.from(await Indices.data()).filter(i => i > 0).map(i => i - 1)
const final = tf.gather(data, tf.tensor1d(indicesArr,"int32"))

i am the wondering when or if the python equivalent tf.boolean_mask will be implemented

# 1-D example
tensor = [0, 1, 2, 3]
mask = np.array([True, False, True, False])
boolean_mask(tensor, mask)  # [0, 2]

Code to reproduce the bug / link to feature request

https://www.tensorflow.org/api_docs/python/tf/boolean_mask

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions