1. 程式人生 > >tensorflow隨筆-條件迴圈控制(9)

tensorflow隨筆-條件迴圈控制(9)

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 27 11:16:32 2018
@author: myhaspl
"""
 
import tensorflow as tf
i = tf.constant(0)
c = lambda i: tf.less(i, 10)
b = lambda i: tf.add(i, 1)
r = tf.while_loop(c, b, [i])
sess=tf.Session()
with sess:
    print sess.run(r)

執行結果為10,函式b的最後執行結果。

迴圈將i每次增加1,直到10

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 27 11:16:32 2018
@author: myhaspl
"""
 
import tensorflow as tf
i = tf.constant(100)
def b(i):
    res=tf.subtract(i, 2)
    return res
    
c = lambda i: tf.greater(i, 0)

r = tf.while_loop(c, b, [i])

sess=tf.Session()
with sess:
    print sess.run(r)

迴圈每次將i減1,直到0

執行結果為0,函式b的最後執行結果。

相關推薦

tensorflow隨筆-條件迴圈控制9

#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Mon Aug 27 11:16:32 2018 @author: myhas

tensorflow隨筆-條件迴圈控制4

tf.no_op tf.no_op(name=None) 什麼都不做,僅做為點位符使用控制邊界。 引數: name: 操作名字(可選) Returns: 建立的操作

tensorflow-條件迴圈控制3

tf.count_up_totf.count_up_to(    ref,    limit,    name=None) 增加“ref”直到它達到“limit” 引數: ref:一個變數,必須是int32, int64型別。必要來自

tensorflow-條件迴圈控制4

例如非嚴格語義的示例:在下面的示例中,計數器i的最終值不依賴於x。while_loop可並行地增加計數器,並更新x。 #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Thu Sep 6 10:16:37 2018 @author

tensorflow隨筆-佇列9

#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Thu Sep 6 10:16:37 2018 @author: myhas

tensorflow-條件循環控制3

created 修改 ini scalar 不同 sca 報錯 count print tf.count_up_totf.count_up_to(? ? ref,? ? limit,? ? name=None) 增加“ref”直到它達到“limit” 參數: ref:一個變

python學習筆記6條件迴圈控制語句

條件迴圈控制語句 if-elif-else語句 格式: if 表示式1: 語句1 elif 表示式2: 語句2 …… elif 表示式n: 語句n else: #可有可無 語句e 邏輯:當程式執行到if-elif-else語句時,首先計算“表示式1”的值,如果“表示式1”的值為真,則

tensorflow-條件循環控制4

const 線程 center spl 例子 sep while 情況下 並行 例如非嚴格語義的示例:在下面的示例中,計數器i的最終值不依賴於x。while_loop可並行地增加計數器,並更新x。 #!/usr/bin/env python2 # -*- coding: u

tensorflow-條件循環控制5

email logic gre logical 1.9 usr sep author name #!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Thu Sep 6 10:16:37 2018 @

Python3 條件控制

語句塊 color str 操作 運算符 實例 簡單 註意 控制 Python條件語句是通過一條或多條語句的執行結果(True或者False)來決定執行的代碼塊。 可以通過下圖來簡單了解條件語句的執行過程: if 語句 Python中if語句的一般形式如下所示: if

TensorFlow從入門到理解:你的第一個迴圈神經網路RNN分類例子

執行程式碼: import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # set random seed for comparing the two result calculations

TensorFlow從入門到理解:你的第一個迴圈神經網路RNN迴歸例子

執行程式碼: import tensorflow as tf import numpy as np import matplotlib.pyplot as plt BATCH_START = 0 TIME_STEPS = 20 BATCH_SIZE = 50 INPUT_SIZE = 1 OUTP

tensorflow-條件迴圈控制(1)

TensorFlow 提供了一些操作和類,您可以使用它們來控制操作的執行,並向圖表新增條件依賴項。 tf.identitytf.tupletf.grouptf.no_optf.count_up_totf.condtf.casetf.while_loop tf.identity  tf.iden

重構-改善既有的程式碼設計-簡化條件表示式9

9.1.分解條件表示式(Decompose Conditional) 9.2.合併條件表示式(Consolidate Conditional Expression) 9.3.合成重複的條件片段(Consolidate Duplicate C

tensorflow-條件迴圈控制(2)

tf.tuple(元組) tf.tuple(    tensors,    name=None,    control_inputs=None) 將多個tensor合併組。 這建立了一

linux學習筆記之shell程式設計流程控制3---for迴圈

for迴圈 語法格式1:指定迴圈範圍 for 變數 in value1 value2... do something done 指令碼例項1 #!/bin/bash for i in 1 2

linux學習筆記之shell程式設計流程控制4while迴圈和until迴圈

while迴圈和until迴圈 ###、 while迴圈 不定迴圈,程式碼格式: while [判斷] do something done 指令碼例項1: #!/bin/bash #從1加到

flink流計算隨筆9

​生成,編譯模板工程 MacBook-Air:SocketWindowWordCount myhaspl$ bash <(curl https://flink.apache.org/q/sbt-q

tensorflow學習9:TFRecord介紹和樣例程式附詳細解讀

由於影象的亮度、對比度等屬性對影象的影響是非常大的,相同物體在不同亮度、對比度下差別非常大,然而在很多影象識別問題中,這些因素都不應該影響最後的識別結果。因此,本文將介紹如何對影象資料處理進行預處理使訓練得到的神經網路模型儘可能小的被無關因素影響。 由於來自實際問題的資料往往有很多格式和

TensorFlow實踐9——普通BP神經網路

(一)前 言 BP(back propagation)神經網路是1986年由Rumelhart和McClelland為首的科學家提出的概念,是一種按照誤差逆向傳播演算法訓練的多層前饋神經網路,是目前應用最廣泛的神經網路。 20世紀80年代中期,David Ru