在张量流中,如何计算张量的行或列范围? 范围为最大-最小
在Matlab中,可以使用“范围”来完成
a=[ 1 2 3; 4 5 6]
range(a) = [3 3 3] %this is the range along columns of a
range(a') = [2 2] %range along rows of a
答案 0 :(得分:0)
您可以执行以下操作
假设(range = max - min
)
# Axis 0
res_1 = tf.reduce_max(a, axis=0) - tf.reduce_min(a, axis=0)
# Axis 1
res_2 = tf.reduce_max(a, axis=1) - tf.reduce_min(a, axis=1)
答案 1 :(得分:0)
使用tf.get_shape()
来获取tensor
的尺寸,您可以在range
函数中进一步使用该尺寸:
import tensorflow as tf
c = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
print(c.get_shape())
>>> TensorShape([Dimension(2), Dimension(3)])
print(c.get_shape()[0].value)
>>> 2