# tf.compat.v2.scalar_mul

<br />

|---|
| [![](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/math_ops.py#L427-L431) |

Multiplies a scalar times a `Tensor` or `IndexedSlices` object.

#### View aliases


**Compat aliases for migration**

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

\`tf.compat.v2.math.scalar_mul\`

<br />

    tf.compat.v2.scalar_mul(
        scalar, x, name=None
    )

Intended for use in gradient code which might deal with `IndexedSlices`
objects, which are easy to multiply by a scalar but more expensive to
multiply with arbitrary tensors.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `scalar` | A 0-D scalar `Tensor`. Must have known shape. |
| `x` | A `Tensor` or `IndexedSlices` to be scaled. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| `scalar * x` of the same type (`Tensor` or `IndexedSlices`) as `x`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | if scalar is not a 0-D `scalar`. |

<br />