erf

paddle.fluid.layers.erf(x)[源代码]

逐元素计算 Erf 激活函数。更多细节请参考 Error function

erf - 图1

参数

  • x (Variable) - Erf Op 的输入,多维 Tensor 或 LoDTensor,数据类型为 float16, float32 或 float64。

返回

  • 多维 Tensor 或 LoDTensor, 数据类型为 float16, float32 或 float64, 和输入 x 的数据类型相同,形状和输入 x 相同。

返回类型

  • Variable

代码示例

  1. # declarative mode
  2. import numpy as np
  3. from paddle import fluid
  4. x = fluid.data(name="x", shape=(-1, 3), dtype="float32")
  5. y = fluid.layers.erf(x)
  6. place = fluid.CPUPlace()
  7. exe = fluid.Executor(place)
  8. start = fluid.default_startup_program()
  9. main = fluid.default_main_program()
  10. data = np.random.randn(2, 3).astype("float32")
  11. exe.run(start)
  12. y_np, = exe.run(main, feed={"x": data}, fetch_list=[y])
  13. data
  14. # array([[ 0.4643714 , -1.1509596 , 1.2538221 ],
  15. # [ 0.34369683, 0.27478245, 1.1805398 ]], dtype=float32)
  16. y_np
  17. # array([[ 0.48863927, -0.8964121 , 0.9237998 ],
  18. # [ 0.37307587, 0.30242872, 0.9049887 ]], dtype=float32)
  1. # imperative mode
  2. import numpy as np
  3. from paddle import fluid
  4. import paddle.fluid.dygraph as dg
  5. data = np.random.randn(2, 3).astype("float32")
  6. place = fluid.CPUPlace()
  7. with dg.guard(place) as g:
  8. x = dg.to_variable(data)
  9. y = fluid.layers.erf(x)
  10. y_np = y.numpy()
  11. data
  12. # array([[ 0.4643714 , -1.1509596 , 1.2538221 ],
  13. # [ 0.34369683, 0.27478245, 1.1805398 ]], dtype=float32)
  14. y_np
  15. # array([[ 0.48863927, -0.8964121 , 0.9237998 ],
  16. # [ 0.37307587, 0.30242872, 0.9049887 ]], dtype=float32)