tf.nest.map_structure() vs map()
发布日期:2021-05-06 23:44:43 浏览次数:36 分类:技术文章

本文共 470 字,大约阅读时间需要 1 分钟。

使用中的一个例子:

def a(x):    return x**2map_ob = map(a,[1,2,3])b = list(map(a,[1,2,3]))c = tf.nest.map_structure(a,[1,2,3])print('b',b,'\nc',c)print('map_ob_type',type(map_ob))print('b_type',type(b))print('c_type',type(c))
b [1, 4, 9] c [1, 4, 9]map_ob_type 
b_type
c_type

对于这两个函数有:

map(func, *iterables)tf.nest.map_structure(func, *structure, **check_types_dict)

也就是说在这个例子里 list(map()) 和 tf.nest.map_structure() 是一样的,因为后者保留了输入的 structure 的数据类型,即列表。

上一篇:联邦学习(一):通过卷积神经网络对 emnist 数据集分类
下一篇:collections 相关函数说明

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年03月10日 02时16分17秒