round

paddle.fluid.layers.round(x, name=None)

The OP rounds the values in the input to the nearest integer value.

input:
  x.shape = [4]
  x.data = [1.2, -0.9, 3.4, 0.9]

output:
  out.shape = [4]
  out.data = [1., -1., 3., 1.]
Parameters
  • x – Input of Round operator, an N-D Tensor, with data type float32, float64 or float16.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name .

Returns

Output of Round operator, a Tensor with shape same as input.

Return type

Variable

System Message: WARNING/2 (/usr/local/lib/python2.7/dist-packages/paddle/fluid/layers/layer_function_generator.py:docstring of paddle.fluid.layers.round, line 22)

Definition list ends without a blank line; unexpected unindent.

Examples

import paddle.fluid as fluid
import numpy as np

inputs = fluid.data(name="x", shape = [None, 4], dtype='float32')
output = fluid.layers.round(inputs)

exe = fluid.Executor(fluid.CPUPlace())
exe.run(fluid.default_startup_program())

#input.shape=1X4, batch_size=1
img = np.array([[1.0, 2.0, 3.0, 4.0]]).astype(np.float32)
res = exe.run(fluid.default_main_program(), feed={'x':img}, fetch_list=[output])
print(res)