# tf.sparse.mask

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 2 version](https://www.tensorflow.org/api_docs/python/tf/sparse/mask) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/array_ops.py#L1563-L1604) |

Masks elements of `IndexedSlices`.

#### View aliases


**Main aliases**

\`tf.sparse_mask\`
**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.sparse.mask`](https://www.tensorflow.org/api_docs/python/tf/sparse/mask), [`tf.compat.v1.sparse_mask`](https://www.tensorflow.org/api_docs/python/tf/sparse/mask), \`tf.compat.v2.sparse.mask\`

<br />

    tf.sparse.mask(
        a, mask_indices, name=None
    )

Given an `IndexedSlices` instance `a`, returns another `IndexedSlices` that
contains a subset of the slices of `a`. Only the slices at indices not
specified in `mask_indices` are returned.

This is useful when you need to extract a subset of slices in an
`IndexedSlices` object.

#### For example:

    # `a` contains slices at indices [12, 26, 37, 45] from a large tensor
    # with shape [1000, 10]
    a.indices  # [12, 26, 37, 45]
    tf.shape(a.values)  # [4, 10]

    # `b` will be the subset of `a` slices at its second and third indices, so
    # we want to mask its first and last indices (which are at absolute
    # indices 12, 45)
    b = tf.sparse.mask(a, [12, 45])

    b.indices  # [26, 37]
    tf.shape(b.values)  # [2, 10]

<br />

<br />

<br />

| ## Args ||
|---|---|
| `a` | An `IndexedSlices` instance. |
| `mask_indices` | Indices of elements to mask. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| The masked `IndexedSlices` instance. ||

<br />