# nonzero¶

`paddle.fluid.layers.``nonzero`(input, as_tuple=False)[源代码]

## 参数¶

• input （Variable）– 输入张量。
• as_tuple (bool, optinal) - 返回格式。是否以 `1-D Tensor` 构成的元组格式返回。

## 返回¶

• Variable (Tensor or tuple(1-D Tensor))，数据类型为 INT64

## 代码示例¶

```import paddle
import numpy as np

data1 = np.array([[1.0, 0.0, 0.0],
[0.0, 2.0, 0.0],
[0.0, 0.0, 3.0]])
data2 = np.array([0.0, 1.0, 0.0, 3.0])
data3 = np.array([0.0, 0.0, 0.0])
with fluid.dygraph.guard():
x1 = fluid.dygraph.to_variable(data1)
x2 = fluid.dygraph.to_variable(data2)
x3 = fluid.dygraph.to_variable(data3)
out_z1 = fluid.layers.nonzero(x1)
print(out_z1.numpy())
#[[0 0]
# [1 1]
# [2 2]]
out_z1_tuple = fluid.layers.nonzero(x1, as_tuple=True)
for out in out_z1_tuple:
print(out.numpy())
#[[0]
# [1]
# [2]]
#[[0]
# [1]
# [2]]
out_z2 = fluid.layers.nonzero(x2)
print(out_z2.numpy())
#[[1]
# [3]]
out_z2_tuple = fluid.layers.nonzero(x2, as_tuple=True)
for out in out_z2_tuple:
print(out.numpy())
#[[1]
# [3]]
out_z3 = fluid.layers.nonzero(x3)
print(out_z3.numpy())
#[]
out_z3_tuple = fluid.layers.nonzero(x3, as_tuple=True)
for out in out_z3_tuple:
print(out.numpy())
#[]
```