megengine.functional.add

add(x, y)[源代码]

逐元素加。至少一个操作数需要是张量。

sub/mul/div/floor_div/pow/mod/atan2/equal/not_equal/less/less_equal/greater/greater_equal/maximum/minmium 同理。

参数

x – 输入张量。

返回

计算得到的张量。

例如:

import numpy as np
from megengine import tensor
import megengine.functional as F

x = tensor(np.arange(0, 6, dtype=np.float32).reshape(2, 3))
y = tensor(np.arange(0, 6, dtype=np.float32).reshape(2, 3))
out = F.add(x, y)
print(out.numpy())

输出:

[[ 0.  2.  4.]
 [ 6.  8. 10.]]