<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/nonZeroIndices(_:name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)nonZeroIndicesOfTensor:name:"
  },
  "title" : "nonZeroIndices(_:name:)"
}
-->

# nonZeroIndices(_:name:)

Computes the indices of the non-zero elements of the input tensor.

```
func nonZeroIndices(_ tensor: MPSGraphTensor, name: String?) -> MPSGraphTensor
```

## Parameters

`tensor`

An MPSGraphTensor of which to compute the non-zero indices.

## Return Value

A valid MPSGraphTensor containing indices in signed int32 data type.

## Discussion

The indices are returned as a two-dimensional tensor of size `[number_of_nonzeros, input_rank]`.
Each row in the result contains indices of a nonzero elements in input.
For example:

```md
tensor = [[ 1,  0, 3],
          [ 0, 10, 0]]
indices = [[ 0, 0],
           [ 0, 2],
           [ 1, 1]]
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)