---
title: "ClikaRT::ops::count_nonzero"
sidebar_label: "count_nonzero"
description: "Number of nonzero elements over dims. Empty dims counts across the whole tensor. Output dtype is always Int64."
---

<!-- Generated by tools/doxygen2mdx from Doxygen XML. Do not edit. -->

<span class="api-kind api-kind--function">function</span>

## count\_nonzero() {#count_nonzero}

<div class="api-signature">

[`Tensor`](../Tensor.md) **`count_nonzero`**([`Tensor`](../Tensor.md) `input`, [`ClikaRT::Span`](../Span.md)`<const std::int64_t>` `dims` `=` `{}`)

</div>

Number of nonzero elements over `dims`.

Empty `dims` counts across the whole tensor. Output dtype is always `Int64`. An element is nonzero exactly when its Bool cast is true: +0 and -0 are zero; a subnormal, an infinity and a NaN are nonzero.

**Parameters**

- `input`: the input tensor; any dtype.
- `dims`: axes to reduce; empty = all axes.

**Returns:** `Int64` counts; shape = `input` minus `dims`.

**Throws**

- `ClikaRT::Error`: (`INVALID_ARGUMENT`) on an out-of-range `dims` entry.

<div class="api-declared">

Declared in `ClikaRT/compute/ops.h`, line 4373

</div>
