Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tensorflow将op应用于二维张量的每个元素_Tensorflow - Fatal编程技术网

Tensorflow将op应用于二维张量的每个元素

Tensorflow将op应用于二维张量的每个元素,tensorflow,Tensorflow,我想要的是对二维张量的每个元素应用张量流运算的能力 input = tf.Variable([[1.0, 2.0], [3.0, 4.0]) myCustomOp = ... # some kind of custom op that operates on 1D tensors finalResult = tf.[thing I'm after](input, myCustomOp) # when run final result should look like: [myCustomOp([

我想要的是对二维张量的每个元素应用张量流运算的能力

input = tf.Variable([[1.0, 2.0], [3.0, 4.0])
myCustomOp = ... # some kind of custom op that operates on 1D tensors
finalResult = tf.[thing I'm after](input, myCustomOp)
# when run final result should look like: [myCustomOp([1.0, 2.0]), myCustomOp([3.0, 4.0)]

有什么想法吗?

TensorFlow的下一个版本(0.8,如果您从源代码构建或下载夜间构建,当前可用)包括并允许您将由TensorFlow ops组成的函数应用于更大tensor的子传感器

tf.map\u fn(fn,elems,…)
函数将
N
维输入
elems
沿第一维解压为多个
N-1
维子传感器,并将
fn
应用于每个子传感器。这似乎非常适合您的用例:

input = tf.Variable([[1.0, 2.0], [3.0, 4.0]])
function_to_map = lambda x: f(x)  # Where `f` instantiates myCustomOp.
final_result = tf.map_fn(function_to_map, input)

也许是地图?文档-谢谢,这正是我想要的,因为
tf.map\u fn
现在已经存在,像
tf.batch\u matrix\u inverse
这样的函数是多余的,因为它们可以被
tf.map\u fn(tf.matrix\u inverse,input)
取代。原则上是的,但实际上
tf.batch\u*()
操作的性能可能会更好。我期待有一天优化器足够好,可以为基于地图的版本生成更好的代码!如果f()的返回维度与输入维度不同,情况会怎样?例如,如果f()返回标量(或任何大小为1的维度数组)?numpy等效物: