简体   繁体   English

是否有 TensorFlow.js 方法可以在特定位置将张量添加到另一个张量?

[英]Is there a TensorFlow.js method to add a tensor to another at a specific location?

Let me make the question clear.让我把问题说清楚。 I have a tensor, just to keep it simple, with zeros.我有一个张量,只是为了简单起见,带有零。 A 2D tensor with shape [3, 3] , call it a :形状为[3, 3]二维张量,称为a

[[0,0,0],
 [0,0,0],
 [0,0,0]]

And I have another tensor, a 2D tensor with shape [2, 2] , call it b , and its just ones:我有另一个张量,一个形状为[2, 2]的二维张量,称为b ,它只是一个:

[[1,1],
 [1,1]]

I want to add them together, but their shapes don't match, and I can't broadcast it as well, but it's not the goal.我想把它们加在一起,但它们的形状不匹配,我也无法播放,但这不是目标。 I want the result of:我想要的结果是:

[[0,0,0],
 [0,1,1],
 [0,1,1]]

And if there would be a method, call it insert for now, I'd have to specify the location where I want to insert the smaller tensor (just as when slicing, defining the start location).如果有一种方法,现在将其称为insert ,我必须指定要插入较小张量的位置(就像切片时定义起始位置一样)。 It would look something like this:它看起来像这样:

a.insert(b, [1, 1])

I was thinking about pad which could produce similar results, but if there would be something like the above, what I might missed, it would be nicer.我正在考虑可以产生类似结果的pad ,但是如果有类似上面的东西,我可能会错过什么,那就更好了。

使用tf.pad ,可以按如下方式完成

padded = tf.ones([2, 2]).pad([[1, 0], [1, 0]])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM