本文整理汇总了Python中tensorflow.python.util.nest.flatten_dict_items方法的典型用法代码示例。如果您正苦于以下问题:Python nest.flatten_dict_items方法的具体用法?Python nest.flatten_dict_items怎么用?Python nest.flatten_dict_items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.util.nest
的用法示例。
在下文中一共展示了nest.flatten_dict_items方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFlattenDictItems
# 需要导入模块: from tensorflow.python.util import nest [as 别名]
# 或者: from tensorflow.python.util.nest import flatten_dict_items [as 别名]
def testFlattenDictItems(self):
dictionary = {(4, 5, (6, 8)): ("a", "b", ("c", "d"))}
flat = {4: "a", 5: "b", 6: "c", 8: "d"}
self.assertEqual(nest.flatten_dict_items(dictionary), flat)
with self.assertRaises(TypeError):
nest.flatten_dict_items(4)
bad_dictionary = {(4, 5, (4, 8)): ("a", "b", ("c", "d"))}
with self.assertRaisesRegexp(ValueError, "not unique"):
nest.flatten_dict_items(bad_dictionary)
another_bad_dictionary = {(4, 5, (6, 8)): ("a", "b", ("c", ("d", "e")))}
with self.assertRaisesRegexp(
ValueError, "Key had [0-9]* elements, but value had [0-9]* elements"):
nest.flatten_dict_items(another_bad_dictionary)