0

How to write multiplication function in normal distribution in Python?

I have an error in my code which is as follows, I want to fix this error.

TypeError:unsupported operand type(s) for *: 'Add' and " NormalDistribution"
2
  • 2
    your code please? Commented Oct 15, 2023 at 15:29
  • 1
    How do you possibly expect us to help, without showing the code?? Commented Oct 15, 2023 at 15:39

1 Answer 1

0

If your question is directly => "How to write multiplication function in normal distribution in Python?"

But, if you ask about your error, you should provide the code (people mentioned in the question comments).

Sample code for it:

import numpy as np
from scipy.stats import norm

mu = 0; sigma = 1
sample = np.random.normal(mu, sigma, size=10) # normal distribution series with numpy
result = sample * 2.0  # multiply with constant 2.0

print(result)

Output:

enter image description here

EDIT (after comments):

I created a sample code for PDF (assumption). I only focus on the multiplication "PDF * (expression)". I neglect the integral part due to the simplification. Maybe if u define it like that, u can express it. It may give u a hint:

Sample Code for multiplication of the distribution and expression:

import sympy as sp

# symbols
X, K_c, mu, sigma = sp.symbols('X K_c mu sigma')

# probability density function f(K_c)
f_Kc = (1 / (sigma * sp.sqrt(2 * sp.pi))) * sp.exp(-((K_c - mu)**2) / (2 * sigma**2))

expression = (X**2 + 2*X) * f_Kc  # <= multiplication example

# set the derivative equal to zero and solve for X
solutions = sp.solve(expression, X)

# Print the solutions
print("Solutions for X:")
for sol in solutions:
    print(sol)

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

I want to code the following statement. Kc = Normal and f(kc)=probability function ∫_(Q_o^high)^∞▒〖s_o φ_o Q_o^high+((1+K_h ) α_1-β_1 Q_o^high-γ_1 Q_o^low )(Q_o^high-K_c W_b1 Q_b^cow )f(K_c )dK_c 〗
your statement cannot be understandable, please refactor your question and showcase it in a minimal reproducible example
Suppose we have a parameter that is random and has a normal distribution (KC). We want to take an integral from an expression, for example (x^2+2x) multiplied by the probability density function of the parameter f(kc). (Integral(x,oo)(x^2+2x)*f(kc)dkc) Then take the derivative of this integral with respect to variable X and set it equal to zero, and the output will be a mathematical formula.
@HadiGholizadeh Please edit your post and add the missing code. Code can be automatically formatted if you add triple backquotes (````) on the lines before and after the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.