megengine.functional.square

square(x)[源代码]

Element-wise square.

实际案例

import numpy as np
import megengine as mge
import megengine.functional as F

data = mge.tensor(np.arange(0, 6, dtype=np.float32).reshape(2, 3))
out = F.square(data)
print(out.numpy().round(decimals=4))

输出:

[[ 0.  1.  4.]
 [ 9. 16. 25.]]
返回类型

Tensor