SlideShare une entreprise Scribd logo
1  sur  7
Télécharger pour lire hors ligne
PythonのYieldを
かじってみた
@24motz
2014-05-03 LT駆動開発03
Pythonの関数
Python 2.7.6 (default, Nov 18 2013, 15:12:51)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
!
>>> def a():
... print "hello"
...
>>> a()
hello
>>> type(a)
<type 'function'>
yieldを含む関数
>>> def hoge():
... yield
...
>>> type(hoge)
<type 'function'>
>>> hoge()
<generator object hoge at 0x1019fda00>
>>> g = hoge()
>>> type(g)
<type 'generator'>
!
yieldを含む関数は

イテレータと同じインタフェースを持つ
呼び出し可能オブジェクト
(ジェネレーター)を返す
イテレーター
>>> def hoge():
... yield 'a'
... yield 'b'
...
>>> g = hoge()
>>> print g.next()
a
>>> print g.next()
b
>>> print g.next()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
シーケンス生成
>>> def hoge():
... yield 'a'
... yield 'b'
...
>>> g = hoge()
>>> for i in g:
... print i
...
a
b
sendメソッド
>>> def hoge():
... s = (yield 'a')
... s = (yield s + 'b')
... s = (yield s + 'c')
...
>>> g = hoge()
>>> print g.send(None)
a
>>> print g.send('x')
xb
>>> print g.send('y')
yc
>>> print g.send('z')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
呼出し側からジェネレータに

値を渡すことができる
ただし
最初の呼び出しは値を渡せない
!
send(None) は next() でも可
最初だけnext()なのは気持ち悪い
状態遷移モデル
def stateManagerGenerator():
while True:
ev = (yield State.FIRST)
if ev == Event.GOTO_SECOND:
break
while True:
ev = (yield State.SECOND)
if ev == Event.GOTO_END:
break
while True:
ev = (yield State.END)
!
sm = stateManagerGenerator()
state = sm.send(None) #=> FIRST
state = sm.send(Event.DUMMY) #=> FIRST
state = sm.send(Event.GOTO_SECOND) #=> SECOND
受け取ったevに応じて
次の状態に進む
状態遷移の規則を
ひとつの関数に
まとめられる

Contenu connexe

Tendances

asm.js x emscripten: The foundation of the next level Web games
asm.js x emscripten: The foundation of the next level Web gamesasm.js x emscripten: The foundation of the next level Web games
asm.js x emscripten: The foundation of the next level Web gamesNoritada Shimizu
 
金曜だけどデザインパターンでも勉強しよう
金曜だけどデザインパターンでも勉強しよう金曜だけどデザインパターンでも勉強しよう
金曜だけどデザインパターンでも勉強しようTakaaki Hirano
 
Perlで伝統芸能
Perlで伝統芸能Perlで伝統芸能
Perlで伝統芸能hitode909
 
10min r study_tokyor25
10min r study_tokyor2510min r study_tokyor25
10min r study_tokyor25Nobuaki Oshiro
 
for文
for文for文
for文APG4b
 
入力
入力入力
入力APG4b
 
Local php-100828 2
Local php-100828 2Local php-100828 2
Local php-100828 2Akio Ishida
 
Good Parts of PHP and the UNIX Philosophy
Good Parts of PHP and the UNIX PhilosophyGood Parts of PHP and the UNIX Philosophy
Good Parts of PHP and the UNIX PhilosophyYuya Takeyama
 
while文
while文while文
while文APG4b
 
[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」
[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」
[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」de:code 2017
 
ひのきのぼうだけで全クリ目指す
ひのきのぼうだけで全クリ目指すひのきのぼうだけで全クリ目指す
ひのきのぼうだけで全クリ目指すAromaBlack
 
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~Fujio Kojima
 
S02 t1 sta_py_tsuji_0702_slides
S02 t1 sta_py_tsuji_0702_slidesS02 t1 sta_py_tsuji_0702_slides
S02 t1 sta_py_tsuji_0702_slidesTakeshi Akutsu
 
実用裏方 Perl 入門
実用裏方 Perl 入門実用裏方 Perl 入門
実用裏方 Perl 入門keroyonn
 
すごいHaskell読書会#10
すごいHaskell読書会#10すごいHaskell読書会#10
すごいHaskell読書会#10Shin Ise
 
Stroustrup11章雑感
Stroustrup11章雑感Stroustrup11章雑感
Stroustrup11章雑感31 00
 
G*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+BetamaxG*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+BetamaxNobuhiro Sue
 

Tendances (19)

asm.js x emscripten: The foundation of the next level Web games
asm.js x emscripten: The foundation of the next level Web gamesasm.js x emscripten: The foundation of the next level Web games
asm.js x emscripten: The foundation of the next level Web games
 
金曜だけどデザインパターンでも勉強しよう
金曜だけどデザインパターンでも勉強しよう金曜だけどデザインパターンでも勉強しよう
金曜だけどデザインパターンでも勉強しよう
 
Perlで伝統芸能
Perlで伝統芸能Perlで伝統芸能
Perlで伝統芸能
 
10min r study_tokyor25
10min r study_tokyor2510min r study_tokyor25
10min r study_tokyor25
 
for文
for文for文
for文
 
入力
入力入力
入力
 
Local php-100828 2
Local php-100828 2Local php-100828 2
Local php-100828 2
 
Good Parts of PHP and the UNIX Philosophy
Good Parts of PHP and the UNIX PhilosophyGood Parts of PHP and the UNIX Philosophy
Good Parts of PHP and the UNIX Philosophy
 
while文
while文while文
while文
 
[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」
[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」
[TL06] 日本の第一人者が C# の現状と今後を徹底解説! 「この素晴らしい C# に祝福を!」
 
ひのきのぼうだけで全クリ目指す
ひのきのぼうだけで全クリ目指すひのきのぼうだけで全クリ目指す
ひのきのぼうだけで全クリ目指す
 
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
C# 式木 (Expression Tree) ~ LINQをより深く理解するために ~
 
S02 t1 sta_py_tsuji_0702_slides
S02 t1 sta_py_tsuji_0702_slidesS02 t1 sta_py_tsuji_0702_slides
S02 t1 sta_py_tsuji_0702_slides
 
実用裏方 Perl 入門
実用裏方 Perl 入門実用裏方 Perl 入門
実用裏方 Perl 入門
 
すごいHaskell読書会#10
すごいHaskell読書会#10すごいHaskell読書会#10
すごいHaskell読書会#10
 
Stroustrup11章雑感
Stroustrup11章雑感Stroustrup11章雑感
Stroustrup11章雑感
 
G*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+BetamaxG*workshop 2011/11/22 Geb+Betamax
G*workshop 2011/11/22 Geb+Betamax
 
F#のすすめ
F#のすすめF#のすすめ
F#のすすめ
 
Teclab3
Teclab3Teclab3
Teclab3
 

Similaire à Python yield

エキ Py 読書会02 2章後半
エキ Py 読書会02 2章後半エキ Py 読書会02 2章後半
エキ Py 読書会02 2章後半Tetsuya Morimoto
 
エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7Tetsuya Morimoto
 
Easy caching and logging package using annotation in Python
Easy caching and logging package using annotation in PythonEasy caching and logging package using annotation in Python
Easy caching and logging package using annotation in PythonYasunori Horikoshi
 
Python東海GAEやってみた
Python東海GAEやってみたPython東海GAEやってみた
Python東海GAEやってみたMori Shingo
 
2017/12/21 虎の穴 Python勉強会
2017/12/21 虎の穴 Python勉強会2017/12/21 虎の穴 Python勉強会
2017/12/21 虎の穴 Python勉強会虎の穴 開発室
 
Replace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JPReplace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JPAkira Takahashi
 
Everyday Life with clojure.spec
Everyday Life with clojure.specEveryday Life with clojure.spec
Everyday Life with clojure.specKent Ohashi
 
エキ Py 読書会02 2章前半
エキ Py 読書会02 2章前半エキ Py 読書会02 2章前半
エキ Py 読書会02 2章前半Tetsuya Morimoto
 
Python Kyoto study
Python Kyoto studyPython Kyoto study
Python Kyoto studyNaoya Inada
 
Hello World Python featuring GAE
Hello World Python featuring GAEHello World Python featuring GAE
Hello World Python featuring GAEMaito Kuwahara
 
Node予備校 vol.1 名古屋
Node予備校 vol.1 名古屋Node予備校 vol.1 名古屋
Node予備校 vol.1 名古屋Mori Shingo
 
Sohu邮箱的python经验
Sohu邮箱的python经验Sohu邮箱的python经验
Sohu邮箱的python经验Ryan Poy
 
社内向けTech Talk資料~Fluentdの基本紹介~
社内向けTech Talk資料~Fluentdの基本紹介~ 社内向けTech Talk資料~Fluentdの基本紹介~
社内向けTech Talk資料~Fluentdの基本紹介~ Daisuke Ikeda
 
イベント駆動プログラミングとI/O多重化
イベント駆動プログラミングとI/O多重化イベント駆動プログラミングとI/O多重化
イベント駆動プログラミングとI/O多重化Gosuke Miyashita
 
Introduction to cython
Introduction to cythonIntroduction to cython
Introduction to cythonAtsuo Ishimoto
 
第3回Webkit/HTML5勉強会 - File APIと加速度センサー
第3回Webkit/HTML5勉強会 - File APIと加速度センサー第3回Webkit/HTML5勉強会 - File APIと加速度センサー
第3回Webkit/HTML5勉強会 - File APIと加速度センサーnakamura001
 
EC-CUBEプラグイン講義
EC-CUBEプラグイン講義EC-CUBEプラグイン講義
EC-CUBEプラグイン講義ria1201
 

Similaire à Python yield (20)

エキ Py 読書会02 2章後半
エキ Py 読書会02 2章後半エキ Py 読書会02 2章後半
エキ Py 読書会02 2章後半
 
エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7エキ Py 読書会02 2010/9/7
エキ Py 読書会02 2010/9/7
 
Easy caching and logging package using annotation in Python
Easy caching and logging package using annotation in PythonEasy caching and logging package using annotation in Python
Easy caching and logging package using annotation in Python
 
Heap statsfx analyzer
Heap statsfx analyzerHeap statsfx analyzer
Heap statsfx analyzer
 
Python東海GAEやってみた
Python東海GAEやってみたPython東海GAEやってみた
Python東海GAEやってみた
 
2017/12/21 虎の穴 Python勉強会
2017/12/21 虎の穴 Python勉強会2017/12/21 虎の穴 Python勉強会
2017/12/21 虎の穴 Python勉強会
 
Replace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JPReplace Output Iterator and Extend Range JP
Replace Output Iterator and Extend Range JP
 
Everyday Life with clojure.spec
Everyday Life with clojure.specEveryday Life with clojure.spec
Everyday Life with clojure.spec
 
エキ Py 読書会02 2章前半
エキ Py 読書会02 2章前半エキ Py 読書会02 2章前半
エキ Py 読書会02 2章前半
 
Python Kyoto study
Python Kyoto studyPython Kyoto study
Python Kyoto study
 
Hello World Python featuring GAE
Hello World Python featuring GAEHello World Python featuring GAE
Hello World Python featuring GAE
 
Node予備校 vol.1 名古屋
Node予備校 vol.1 名古屋Node予備校 vol.1 名古屋
Node予備校 vol.1 名古屋
 
Sohu邮箱的python经验
Sohu邮箱的python经验Sohu邮箱的python经验
Sohu邮箱的python经验
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
 
社内向けTech Talk資料~Fluentdの基本紹介~
社内向けTech Talk資料~Fluentdの基本紹介~ 社内向けTech Talk資料~Fluentdの基本紹介~
社内向けTech Talk資料~Fluentdの基本紹介~
 
イベント駆動プログラミングとI/O多重化
イベント駆動プログラミングとI/O多重化イベント駆動プログラミングとI/O多重化
イベント駆動プログラミングとI/O多重化
 
Ajax 応用
Ajax 応用Ajax 応用
Ajax 応用
 
Introduction to cython
Introduction to cythonIntroduction to cython
Introduction to cython
 
第3回Webkit/HTML5勉強会 - File APIと加速度センサー
第3回Webkit/HTML5勉強会 - File APIと加速度センサー第3回Webkit/HTML5勉強会 - File APIと加速度センサー
第3回Webkit/HTML5勉強会 - File APIと加速度センサー
 
EC-CUBEプラグイン講義
EC-CUBEプラグイン講義EC-CUBEプラグイン講義
EC-CUBEプラグイン講義
 

Plus de Takuya Nishimoto

221217 SwiftはPythonに似ている
221217 SwiftはPythonに似ている221217 SwiftはPythonに似ている
221217 SwiftはPythonに似ているTakuya Nishimoto
 
220427-pydata 統計・データ分析 特集
220427-pydata 統計・データ分析 特集220427-pydata 統計・データ分析 特集
220427-pydata 統計・データ分析 特集Takuya Nishimoto
 
220126 python-datalake-spark
220126 python-datalake-spark220126 python-datalake-spark
220126 python-datalake-sparkTakuya Nishimoto
 
211120 他人の書いたPythonスクリプトをステップ実行で理解する
211120 他人の書いたPythonスクリプトをステップ実行で理解する211120 他人の書いたPythonスクリプトをステップ実行で理解する
211120 他人の書いたPythonスクリプトをステップ実行で理解するTakuya Nishimoto
 
211020 すごい広島 with OSH 2021.10
211020 すごい広島 with OSH 2021.10211020 すごい広島 with OSH 2021.10
211020 すごい広島 with OSH 2021.10Takuya Nishimoto
 
210917 オープンセミナー@広島のこれまでとこれから
210917 オープンセミナー@広島のこれまでとこれから210917 オープンセミナー@広島のこれまでとこれから
210917 オープンセミナー@広島のこれまでとこれからTakuya Nishimoto
 
210911 これから始める電子工作とMicroPython
210911 これから始める電子工作とMicroPython210911 これから始める電子工作とMicroPython
210911 これから始める電子工作とMicroPythonTakuya Nishimoto
 
210526 Power Automate Desktop Python
210526 Power Automate Desktop Python210526 Power Automate Desktop Python
210526 Power Automate Desktop PythonTakuya Nishimoto
 
191208 python-kansai-nishimoto
191208 python-kansai-nishimoto191208 python-kansai-nishimoto
191208 python-kansai-nishimotoTakuya Nishimoto
 
191101 nvda-sightworld-nishimoto
191101 nvda-sightworld-nishimoto191101 nvda-sightworld-nishimoto
191101 nvda-sightworld-nishimotoTakuya Nishimoto
 
190916 nishimoto-nvda-pyconjp
190916 nishimoto-nvda-pyconjp190916 nishimoto-nvda-pyconjp
190916 nishimoto-nvda-pyconjpTakuya Nishimoto
 

Plus de Takuya Nishimoto (20)

221217 SwiftはPythonに似ている
221217 SwiftはPythonに似ている221217 SwiftはPythonに似ている
221217 SwiftはPythonに似ている
 
220427-pydata 統計・データ分析 特集
220427-pydata 統計・データ分析 特集220427-pydata 統計・データ分析 特集
220427-pydata 統計・データ分析 特集
 
220126 python-datalake-spark
220126 python-datalake-spark220126 python-datalake-spark
220126 python-datalake-spark
 
211120 他人の書いたPythonスクリプトをステップ実行で理解する
211120 他人の書いたPythonスクリプトをステップ実行で理解する211120 他人の書いたPythonスクリプトをステップ実行で理解する
211120 他人の書いたPythonスクリプトをステップ実行で理解する
 
211020 すごい広島 with OSH 2021.10
211020 すごい広島 with OSH 2021.10211020 すごい広島 with OSH 2021.10
211020 すごい広島 with OSH 2021.10
 
210917 オープンセミナー@広島のこれまでとこれから
210917 オープンセミナー@広島のこれまでとこれから210917 オープンセミナー@広島のこれまでとこれから
210917 オープンセミナー@広島のこれまでとこれから
 
210911 これから始める電子工作とMicroPython
210911 これから始める電子工作とMicroPython210911 これから始める電子工作とMicroPython
210911 これから始める電子工作とMicroPython
 
210728 mpy
210728 mpy210728 mpy
210728 mpy
 
210630 python
210630 python210630 python
210630 python
 
210526 Power Automate Desktop Python
210526 Power Automate Desktop Python210526 Power Automate Desktop Python
210526 Power Automate Desktop Python
 
210428 python
210428 python210428 python
210428 python
 
200918 hannari-python
200918 hannari-python200918 hannari-python
200918 hannari-python
 
200429 python
200429 python200429 python
200429 python
 
200325 flask
200325 flask200325 flask
200325 flask
 
200208 osh-nishimoto-v2
200208 osh-nishimoto-v2200208 osh-nishimoto-v2
200208 osh-nishimoto-v2
 
191208 python-kansai-nishimoto
191208 python-kansai-nishimoto191208 python-kansai-nishimoto
191208 python-kansai-nishimoto
 
191101 nvda-sightworld-nishimoto
191101 nvda-sightworld-nishimoto191101 nvda-sightworld-nishimoto
191101 nvda-sightworld-nishimoto
 
191114 iotlt-nishimoto
191114 iotlt-nishimoto191114 iotlt-nishimoto
191114 iotlt-nishimoto
 
191030 anna-with-python
191030 anna-with-python191030 anna-with-python
191030 anna-with-python
 
190916 nishimoto-nvda-pyconjp
190916 nishimoto-nvda-pyconjp190916 nishimoto-nvda-pyconjp
190916 nishimoto-nvda-pyconjp
 

Dernier

知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptxsn679259
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...Toru Tamaki
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイスCRI Japan, Inc.
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Gamesatsushi061452
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsWSO2
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルCRI Japan, Inc.
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。iPride Co., Ltd.
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video UnderstandingToru Tamaki
 

Dernier (10)

知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
知識ゼロの営業マンでもできた!超速で初心者を脱する、悪魔的学習ステップ3選.pptx
 
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
論文紹介:Video-GroundingDINO: Towards Open-Vocabulary Spatio-Temporal Video Groun...
 
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
LoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイスLoRaWANスマート距離検出センサー  DS20L  カタログ  LiDARデバイス
LoRaWANスマート距離検出センサー DS20L カタログ LiDARデバイス
 
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
論文紹介: The Surprising Effectiveness of PPO in Cooperative Multi-Agent Games
 
Utilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native IntegrationsUtilizing Ballerina for Cloud Native Integrations
Utilizing Ballerina for Cloud Native Integrations
 
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その32024/04/26の勉強会で発表されたものです。
 
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアルLoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
LoRaWAN スマート距離検出デバイスDS20L日本語マニュアル
 
新人研修 後半 2024/04/26の勉強会で発表されたものです。
新人研修 後半        2024/04/26の勉強会で発表されたものです。新人研修 後半        2024/04/26の勉強会で発表されたものです。
新人研修 後半 2024/04/26の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
Amazon SES を勉強してみる その22024/04/26の勉強会で発表されたものです。
 
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
論文紹介:Selective Structured State-Spaces for Long-Form Video Understanding
 

Python yield

  • 2. Pythonの関数 Python 2.7.6 (default, Nov 18 2013, 15:12:51) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin Type "help", "copyright", "credits" or "license" for more information. ! >>> def a(): ... print "hello" ... >>> a() hello >>> type(a) <type 'function'>
  • 3. yieldを含む関数 >>> def hoge(): ... yield ... >>> type(hoge) <type 'function'> >>> hoge() <generator object hoge at 0x1019fda00> >>> g = hoge() >>> type(g) <type 'generator'> ! yieldを含む関数は
 イテレータと同じインタフェースを持つ 呼び出し可能オブジェクト (ジェネレーター)を返す
  • 4. イテレーター >>> def hoge(): ... yield 'a' ... yield 'b' ... >>> g = hoge() >>> print g.next() a >>> print g.next() b >>> print g.next() Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration
  • 5. シーケンス生成 >>> def hoge(): ... yield 'a' ... yield 'b' ... >>> g = hoge() >>> for i in g: ... print i ... a b
  • 6. sendメソッド >>> def hoge(): ... s = (yield 'a') ... s = (yield s + 'b') ... s = (yield s + 'c') ... >>> g = hoge() >>> print g.send(None) a >>> print g.send('x') xb >>> print g.send('y') yc >>> print g.send('z') Traceback (most recent call last): File "<stdin>", line 1, in <module> StopIteration 呼出し側からジェネレータに
 値を渡すことができる ただし 最初の呼び出しは値を渡せない ! send(None) は next() でも可 最初だけnext()なのは気持ち悪い
  • 7. 状態遷移モデル def stateManagerGenerator(): while True: ev = (yield State.FIRST) if ev == Event.GOTO_SECOND: break while True: ev = (yield State.SECOND) if ev == Event.GOTO_END: break while True: ev = (yield State.END) ! sm = stateManagerGenerator() state = sm.send(None) #=> FIRST state = sm.send(Event.DUMMY) #=> FIRST state = sm.send(Event.GOTO_SECOND) #=> SECOND 受け取ったevに応じて 次の状態に進む 状態遷移の規則を ひとつの関数に まとめられる