coin関数の確率pを最大化する独習で問題を解いております。
python
1from pulp import * 2import math 3 4def combinations_count(n, r): 5 return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) 6 7def coin(p, trial, success): 8 cul = (combinations_count(trial, success))*(pow(p, success))*(pow((1-p),(trial-success))) 9 return cul 10 11m = LpProblem(sense=LpMaximize) 12x = LpVariable('x', cat=LpBinary) 13m += coin(x, 100, 70) 14m.solve() 15print(value(x)) 16value(m.objective)
以下のようなエラーが出て困っています。
型が間違っているような感じですが対応策がわかりません。
m += coin(x, 100, 70) File "<ipython-input-37-7db0d6571179>", line 2, in coin cul = (combinations_count(trial, success))*(pow(p, success))*(pow((1-p),(trial-success))) TypeError: unsupported operand type(s) for ** or pow(): 'LpVariable' and 'int'
よろしくお願いいたします。
環境
windows10, Python3.6
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。