elementwise_floordiv¶
该OP是逐元素整除算子,输入 x
与输入 y
逐元素整除,并将各个位置的输出元素保存到返回结果中。
等式为:
\[Out = X // Y\]
\(X\):多维Tensor。
\(Y\):维度必须小于等于X维度的Tensor。
- 对于这个运算算子有2种情况:
-
\(Y\) 的
shape
与 \(X\) 相同。\(Y\) 的
shape
是 \(X\) 的连续子序列。
- 对于情况2:
-
用 \(Y\) 匹配 \(X\) 的形状(shape),其中
axis
是 \(Y\) 在 \(X\) 上的起始维度的位置。如果
axis
为-1(默认值),则 \(axis= rank(X)-rank(Y)\) 。考虑到子序列,\(Y\) 的大小为1的尾部维度将被忽略,例如shape(Y)=(2,1)=>(2)。
例如:
shape(X) = (2, 3, 4, 5), shape(Y) = (,)
shape(X) = (2, 3, 4, 5), shape(Y) = (5,)
shape(X) = (2, 3, 4, 5), shape(Y) = (4, 5), with axis=-1(default) or axis=2
shape(X) = (2, 3, 4, 5), shape(Y) = (3, 4), with axis=1
shape(X) = (2, 3, 4, 5), shape(Y) = (2), with axis=0
shape(X) = (2, 3, 4, 5), shape(Y) = (2, 1), with axis=0
参数¶
返回¶
维度与
x
相同的Tensor
或LoDTensor
,数据类型与x
相同。
返回类型¶
Variable。
代码示例 1¶
import paddle.fluid as fluid
import numpy as np
def gen_data():
return {
"x": np.array([2, 3, 4]),
"y": np.array([1, 5, 2])
}
x = fluid.data(name="x", shape=[3], dtype='int64')
y = fluid.data(name="y", shape=[3], dtype='int64')
z = fluid.layers.elementwise_floordiv(x, y)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(), fetch_list=[z.name])
print(z_value) #[2,0,2]
代码示例 2¶
import paddle.fluid as fluid
import numpy as np
def gen_data():
return {
"x": np.random.randint(1, 5, size=[2, 3, 4, 5]),
"y": np.random.randint(1, 5, size=[3, 4])
}
x = fluid.data(name="x", shape=[2,3,4,5], dtype='int64')
y = fluid.data(name="y", shape=[3,4], dtype='int64')
z = fluid.layers.elementwise_floordiv(x, y, axis=1)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value) # z.shape=[2,3,4,5]
代码示例 3¶
import paddle.fluid as fluid
import numpy as np
def gen_data():
return {
"x": np.random.randint(1, 5, size=[2, 3, 4, 5]),
"y": np.random.randint(1, 5, size=[5])
}
x = fluid.data(name="x", shape=[2,3,4,5], dtype='int64')
y = fluid.data(name="y", shape=[5], dtype='int64')
z = fluid.layers.elementwise_floordiv(x, y, axis=3)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
z_value = exe.run(feed=gen_data(),
fetch_list=[z.name])
print(z_value) # z.shape=[2,3,4,5]