mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Update openmc/stats/univariate.py
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
parent
aba235e0b4
commit
0c3d30e6d1
1 changed files with 1 additions and 8 deletions
|
|
@ -139,14 +139,7 @@ class Discrete(Univariate):
|
|||
def sample(self, n_samples=1, seed=None):
|
||||
np.random.seed(seed)
|
||||
|
||||
if len(self.x) == 1:
|
||||
return np.full((n_samples), self.x[0])
|
||||
|
||||
xi = np.random.rand(n_samples)
|
||||
out = np.zeros_like(xi)
|
||||
for i, c in enumerate(self.cdf()[:-1]):
|
||||
out[xi >= c] = self.x[i]
|
||||
return out
|
||||
return np.random.choice(self.x, n_samples, p=self.p)
|
||||
|
||||
def normalize(self):
|
||||
norm = sum(self.p)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue