tensorflow map_fn 是否支持采用多个张量? [英] Does tensorflow map_fn support taking more than one tensor?

查看:31
本文介绍了tensorflow map_fn 是否支持采用多个张量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tf.map_fn 是否支持采用多个张量,如 python 的原生 map 函数所支持的那样(下面提供了示例)?

a = [1,2,3,4]b = [17,12,11,10]打印(地图(拉姆达 x,y:x+y,a,b))# ==>[18, 14, 14, 14]

解决方案

今天,我看到 map_fn 被增强为采用两个张量,如文档所述 - elems:张量或(可能嵌套的)张量序列,每个都将沿着它们的第一个维度解包.结果切片的嵌套序列将应用于 fn."该示例(尽管以 numpy 形式给出)还表明它可以采用两个张量.我在这里复制.

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

来源:

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]

解决方案

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:

这篇关于tensorflow map_fn 是否支持采用多个张量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆