Home/Support/Support Forum/Python define function
New and improved user forum site going live on 12/6 (All users will need to reset their password when the new forum is active)
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Python define function

0 votes
The following Error Message shows up in the last 'Plot' procedure: In Z(Q), 'numpy.float64' object is not iterable.

I would like Z(Q) returns value that sum each i in the range (0, len(p)), which is a function with variable Q. And finally the plot is Q(X Axis) and Z(Q)(Y Axis) for each Q it can be plotted.

How can I modify Z(Q)? Thank you!

import numpy as np
import scipy.stats as stats
from scipy.stats import poisson, norm

cs = 100
co = 300
mu = 4.7

G = poisson(mu)
p = G.pmf(np.arange(3*mu))

# Define Z(Q) function

def Z(Q):
for i in range(len(p)):
return sum(p*cs*max((Q-i), 0) + p*co*max((i-Q), 0))

# Plot Q and (Q)

import pylab as pl

x = []
y = []

for Q in range(0, 12):

pl.plot(x, y, '-o')
asked Apr 10, 2017 in 3rd Party Python and API development in other Languages by Crubal New to the Community (0 points)

Please log in or register to answer this question.

1 Answer

0 votes
What product is this being used with?
answered Apr 10, 2017 by mvut Veteran of the Digi Community (15,515 points)