标签:coding ssi import utf-8 pre python2 lambda pair point
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 27 11:16:32 2018
@author: myhaspl
"""
import tensorflow as tf
import collections
Pair = collections.namedtuple(‘Pair‘, ‘j, k‘)
ijk_0 = (tf.constant(0), Pair(tf.constant(1), tf.constant(2)))
c = lambda i, p: i < 10
b = lambda i, p: (i + 1, Pair((p.j + p.k), (p.j - p.k)))
ijk_final = tf.while_loop(c, b, ijk_0)
sess=tf.Session()
with sess:
print sess.run(ijk_final)
(10, Pair(j=32, k=64))
循环,以命名元组Pair的值为初值,每次循环将其j更新为j+k,k更新为j-k,并返回一个新的命名元组对象。
>>> from collections import namedtuple
>>> Point = namedtuple(‘Point‘, [‘x‘, ‘y‘])
>>> p = Point(12, y=16)
>>> p
Point(x=12, y=16)
>>> p.x + p.y
28
>>> p[0] + p[1]
28
>>> x, y = p
>>> x
12
>>> y
16
标签:coding ssi import utf-8 pre python2 lambda pair point
原文地址:http://blog.51cto.com/13959448/2334195