isfinite

paddle.fluid.layers.isfinite(x)[source]

Test if any of x contains an infinity / nan number. If all the elements are finite, returns true, else false.

Note: The input to this operator Tensor / LoDTensor data type must be one of int32 / float / double.

Parameters

x (Variable) – The Tensor / LoDTensor to be checked.

Returns

The tensor variable storing the output, contains a bool value.

Return type

Variable

Examples

import paddle.fluid as fluid
import numpy

# Graph Organizing
var = fluid.data(name="data", shape=(4, 6), dtype="float32")
output = fluid.layers.isfinite(var)

# Create an executor using CPU as an example
exe = fluid.Executor(fluid.CPUPlace())

# Execute
img = numpy.ones((4, 6)).astype(numpy.float32)
res, = exe.run(fluid.default_main_program(), feed={'data':img}, fetch_list=[output])
print(res)  # Output Value: [ True]