Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does tensorflow map_fn support taking more than one tensor?

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]
like image 209
A Das Avatar asked May 07 '16 08:05

A Das


People also ask

What does TF Map_fn do?

map_fn also supports functions with multi-arity inputs and outputs: If elems is a tuple (or nested structure) of tensors, then those tensors must all have the same outer-dimension size ( num_elems ); and fn is used to transform each tuple (or structure) of corresponding slices from elems .

What is TF constant?

tf. constant is useful for asserting that the value can be embedded that way. If the argument dtype is not specified, then the type is inferred from the type of value . # Constant 1-D Tensor from a python list. tf.

What is TF scan?

A tensor or (possibly nested) sequence of tensors. Each tensor packs the results of applying fn to tensors unpacked from elems along the first dimension, and the previous accumulator value(s), from first to last (or last to first, if reverse=True ).


1 Answers

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.

elems = (np.array([1, 2, 3]), np.array([-1, 1, -1]))
alternate = map_fn(lambda x: x[0] * x[1], elems, dtype=tf.int64)
# alternate == [-1, 2, -3]

Source:

like image 117
A Das Avatar answered Sep 27 '22 22:09

A Das