cythonファイルに型を定義したいです
もともとのpyxファイルと
自分で型を定義したときのコードをのせます
python
1gamma1.pyx 2 3from math import exp 4def gamma(word_all, word_topic): 5 c = exp(w_all+w_topic) / (sum([exp(wall + wtopic) for wall, wtopic in zip(word_all, word_topic)])) 6 return c 7------------------------------------------------------- 8from math import exp 9 10cdef gamma(float word_all, float word_topic): 11 c = exp(w_all+w_topic) / (sum([exp(wall + wtopic) for wall, wtopic in zip(word_all, word_topic)])) 12 return c 13 14-------------------------------------------------------- 15引数はこのような形です 16In [2]: word_all 17Out[2]: [0.2, 0.2, 0.2, 0.2, 0.2] 18In [7]: word_topic 19Out[7]: 20[[0.02, 0.02, 0.02, 0.02, 0.02], 21 [0.02, 0.02, 0.02, 0.02, 0.02], 22 [0.02, 0.02, 0.02, 0.02, 0.02], 23 [0.02, 0.02, 0.02, 0.02, 0.02], 24 [0.02, 0.02, 0.02, 0.02, 0.02], 25 [0.02, 0.02, 0.02, 0.02, 0.02], 26 [0.02, 0.02, 0.02, 0.02, 0.02], 27 [0.02, 0.02, 0.02, 0.02, 0.02], 28 [0.02, 0.02, 0.02, 0.02, 0.02], 29 [0.02, 0.02, 0.02, 0.02, 0.02]] 30
このような型の定義の仕方で大丈夫でしょうか
回答1件
あなたの回答
tips
プレビュー