Does tf.map_fn support taking more than one tensors as is supported by python's native map function (example provided below)?
a = [1,2,3,4]
b = [17,12,11,10]
print(map(lambda x,y:x+y, a,b)) # ==> [18, 14, 14, 14]
Does tf.map_fn support taking more than one tensors as is supported by python's native map function (example provided below)?
a = [1,2,3,4]
b = [17,12,11,10]
print(map(lambda x,y:x+y, a,b)) # ==> [18, 14, 14, 14]
Not natively, but here's a quick function that achieves it:
As on today, I see that map_fn is enhanced to take two tensors as the documentation says that - "elems: A tensor or (possibly nested) sequence of tensors, each of which will be unpacked along their first dimension. The nested sequence of the resulting slices will be applied to fn." The example (though given in numpy form) also shows that it can take two tensors. I'm copying it here.
Source:
you can combine approaches described in this page to pass a number of tensors and arguments to be considered when calling to your function, for example -
The source code shows that this function takes only one elems tensor:
I don't see any * and ** parameters.
If Tensors are of the same shape (most cases), stack the tensors in the first dimension and slide them inside the map function:
reference LINK