0

Is there a way to use one copy of simulated random variable in one line in Python (without defining a new function)?

For example, if I need to evaluate f(x) = x + sin(x) for normal random variable, I will write x = norm.rvs() then the next line x + sin(x). If I do norm.rvs() + sin(norm.rvs()) this is equivalent to simulating two independent copies of random variables, which is not what I want to do.

Georgy
  • 12,464
  • 7
  • 65
  • 73
ZHU
  • 904
  • 1
  • 11
  • 25
  • 4
    Not prior to the implementation of [PEP 572](https://www.python.org/dev/peps/pep-0572/). – jonrsharpe Jul 04 '18 at 06:32
  • ... and the scheduled release date of version 3.8 is 2019-OCT-20 (PEP 569) – VPfB Jul 04 '18 at 06:48
  • Related: https://stackoverflow.com/questions/49671990/nested-lambda-statements-when-sorting-lists – Georgy Jul 04 '18 at 06:49
  • Possible duplicate of [Variable assignment in expressions](https://stackoverflow.com/questions/4161578/variable-assignment-in-expressions) – Georgy Dec 13 '18 at 14:49

0 Answers0