JSFiddle包含:
import numpy as np
import scipy.stats as stats
from scipy.stats import poisson, norm
mu = 4.68
cs = 100
co = 300
G = poisson(mu)
p = G.pmf(np.arange(3*mu))
def Z(Q):
ES = sum(i*p[i] for i in range(len(p)))
return co*max((Q-ES), 0) + cs*max((ES-Q), 0)
Qstar = np.ceil(poisson.ppf(co/(cs+co), mu))
print(Qstar)
Qstar = int(np.float64(Qstar).item())
from scipy.integrate import quad
import pylab as pl
x = []
y = []
for Q in range(0, Qstar):
x.append(Q)
y.append(Z(Q))
pl.plot(x, y)
pl.show()
为什么var d = " " + true ? "am" : "pm";
var e = " " + "am";
alert("|" + d + "|");
alert("|" + e + "|");
不包含前导空格?
答案 0 :(得分:2)
你想要var d = " " + (true ? "am" : "pm")
答案 1 :(得分:1)
javascript操作顺序是在三元运算符之前计算" " + true
。
答案 2 :(得分:1)
“”+ true计算为布尔值..你需要
var d = " " + (true ? "am" : "pm");
答案 3 :(得分:1)
你正试图这样做
var d = (" " + true) ? "am" : "pm"
在您的情况下,条件为" " + true
。
正确的条件是var d = (true ? "am" : "pm")
var d = " " + true ? "am" : "pm"; //output |am|
var d = (" " + true) ? "am" : "pm"; //output |am|
var d = " " + (true ? "am" : "pm"); //output | am|