Reduces input along the dimensions given in axis.
Unless keepdims is true, the rank of the tensor is reduced by 1 for each
entry in axis. If keepdims is true, the reduced dimensions
are retained with length 1.
If axis has no entries, all dimensions are reduced, and a
tensor with a single element is returned.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.math.count_nonzero\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/math_ops.py#L2347-L2420) |\n\nComputes number of nonzero elements across dimensions of a tensor. \n\n tf.math.count_nonzero(\n input,\n axis=None,\n keepdims=None,\n dtype=../../tf/dtypes#int64,\n name=None\n )\n\nReduces `input` along the dimensions given in `axis`.\nUnless `keepdims` is true, the rank of the tensor is reduced by 1 for each\nentry in `axis`. If `keepdims` is true, the reduced dimensions\nare retained with length 1.\n\nIf `axis` has no entries, all dimensions are reduced, and a\ntensor with a single element is returned.\n| **Note:** Floating point comparison to zero is done by exact floating point equality check. Small values are **not** rounded to zero for purposes of the nonzero check.\n\n#### For example:\n\n x = tf.constant([[0, 1, 0], [1, 1, 0]])\n tf.math.count_nonzero(x) # 3\n tf.math.count_nonzero(x, 0) # [1, 2, 0]\n tf.math.count_nonzero(x, 1) # [1, 2]\n tf.math.count_nonzero(x, 1, keepdims=True) # [[1], [2]]\n tf.math.count_nonzero(x, [0, 1]) # 3\n\n| **Note:** Strings are compared against zero-length empty string `\"\"`. Any string with a size greater than zero is already considered as nonzero.\n\n#### For example:\n\n x = tf.constant([\"\", \"a\", \" \", \"b\", \"\"])\n tf.math.count_nonzero(x) # 3, with \"a\", \" \", and \"b\" as nonzero strings.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|--------------------------------------------------------------------------------------------------------------------------------|\n| `input` | The tensor to reduce. Should be of numeric type, `bool`, or `string`. |\n| `axis` | The dimensions to reduce. If `None` (the default), reduces all dimensions. Must be in the range `[-rank(input), rank(input))`. |\n| `keepdims` | If true, retains reduced dimensions with length 1. |\n| `dtype` | The output dtype; defaults to [`tf.int64`](../../tf#int64). |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The reduced tensor (number of nonzero values). ||\n\n\u003cbr /\u003e"]]