<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/array_ops.py#L762-L799) |

Returns the size of a tensor.

    tf.size(
        input, out_type=None, name=None
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Matrix approximation with Core APIs](https://www.tensorflow.org/guide/core/matrix_core) - [Introduction to Tensors](https://www.tensorflow.org/guide/tensor) - [BERT Preprocessing with TF Text](https://www.tensorflow.org/text/guide/bert_preprocessing_guide) | - [Scalable model compression](https://www.tensorflow.org/tutorials/optimization/compression) - [Sending Different Data To Particular Clients With federated_language.federated_select](https://www.tensorflow.org/federated/tutorials/federated_select) - [Human Pose Classification with MoveNet and TensorFlow Lite](https://www.tensorflow.org/lite/tutorials/pose_classification) - [Federated Learning for Image Classification](https://www.tensorflow.org/federated/tutorials/federated_learning_for_image_classification) |

See also [`tf.shape`](https://www.tensorflow.org/api_docs/python/tf/shape).

Returns a 0-D `Tensor` representing the number of elements in `input`
of type `out_type`. Defaults to tf.int32.

#### For example:

    t = tf.constant([[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]]])
    tf.size(t)
    <tf.Tensor: shape=(), dtype=int32, numpy=12>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `input` | A `Tensor` or `SparseTensor`. |
| `out_type` | (Optional) The specified non-quantized numeric output type of the operation. Defaults to [`tf.int32`](https://www.tensorflow.org/api_docs/python/tf#int32). (Note: there is an experimental flag, `tf_shape_default_int64` that changes the default to [`tf.int64`](https://www.tensorflow.org/api_docs/python/tf#int64). This is an unsupported, experimental setting that causes known breakages.) |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` of type `out_type`. Defaults to [`tf.int32`](https://www.tensorflow.org/api_docs/python/tf#int32). ||

<br />

<br />

## numpy compatibility

<br />

Equivalent to np.size()

<br />

<br />