%
is the prefix for invoking magic line functions within IPython's interactive shell and there is no z
line magic function, hence you get this error.
type %quickref
in IPython and you get an overview over the available magic functions or readthedocs.
Your problem was that you were trying too much in one step. Try getting the right result for one input and then accumulate in another step:
def calc(mean_, limit_):
def inner(m, s):
r = poisson(m)
l = []
z = 0
while True:
y = r.pmf(z)
l.append(y)
z += 1
if round(sum(l), 2) * 100 >= s:
return z, l
return [inner(*args) for args in zip(mean_, limit_)]
Calling calc(mean, limit)
gives:
[(10,
[0.0031511115984444414,
0.018150402807039979,
0.052273160084275148,
0.10036446736180832,
0.14452483300100394,
0.16649260761715656,
0.15983290331247035,
0.13151964615426115,
0.094694145231068075,
0.060604252947883679]),
(10,
[0.0015034391929775724,
0.009772354754354215,
0.031760152951651209,
0.068813664728577653,
0.11182220518393866,
0.14536886673912017,
0.1574829389673803,
0.14623415761256733,
0.11881525306021086,
0.08581101609904139]),
(12,
[0.00091188196555451624,
0.0063831737588816145,
0.022341108156085643,
0.052129252364199796,
0.091226191637349643,
0.1277166682922895,
0.14900277967433773,
0.14900277967433773,
0.1303774322150455,
0.10140466950059107,
0.070983268650413558,
0.045171170959354162]),
(10,
[0.006737946999085467,
0.033689734995427337,
0.084224337488568321,
0.1403738958142805,
0.17546736976785063,
0.17546736976785068,
0.1462228081398754,
0.10444486295705395,
0.065278039348158651,
0.036265577415643714]),
(10,
[0.011108996538242306,
0.049990484422090385,
0.11247858994970336,
0.168717884924555,
0.18980762054012446,
0.17082685848611215,
0.1281201438645839,
0.082362949627232548,
0.046329159165318316,
0.0231645795826592]),
(9,
[0.0024787521766663585,
0.014872513059998144,
0.044617539179994441,
0.089235078359988937,
0.13385261753998332,
0.16062314104797995,
0.16062314104798009,
0.13767697804112569,
0.10325773353084421]),
(13,
[0.00012340980408667956,
0.0011106882367801166,
0.0049980970655105232,
0.014994291196531574,
0.033737155192196056,
0.06072687934595293,
0.091090319018929264,
0.1171161244529091,
0.13175564000952278,
0.13175564000952278,
0.11858007600857066,
0.097020062188830414,
0.072765046641622894]),
(4,
[0.0820849986238988,
0.20521249655974699,
0.25651562069968376,
0.21376301724973648]),
(6,
[0.049787068367863944,
0.14936120510359185,
0.22404180765538775,
0.22404180765538775,
0.16803135574154085,
0.10081881344492458]),
(10,
[0.0040867714384640666,
0.02247724291155237,
0.06181241800676901,
0.1133227663457432,
0.15581880372539689,
0.17140068409793663,
0.15711729375644187,
0.12344930223720431,
0.084871395288077939,
0.051865852676047694])]