mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 06:05:58 -04:00
Using np.random.choice in Mixture class
This commit is contained in:
parent
967fc9f88b
commit
f92ea393f2
1 changed files with 2 additions and 5 deletions
|
|
@ -1135,12 +1135,9 @@ class Mixture(Univariate):
|
|||
|
||||
def sample(self, n_samples=1, seed=None):
|
||||
np.random.seed(seed)
|
||||
xi = np.random.rand(n_samples)
|
||||
idx = np.zeros_like(xi, dtype=int)
|
||||
for i, c in enumerate(self.cdf()[:-1]):
|
||||
idx[xi >= c] = i
|
||||
idx = np.random.choice(self.distribution, n_samples, p=self.probability)
|
||||
|
||||
out = np.zeros_like(xi)
|
||||
out = np.zeros_like(idx)
|
||||
for i in np.unique(idx):
|
||||
n_dist_samples = np.count_nonzero(idx == i)
|
||||
samples = self.distribution[i].sample(n_dist_samples)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue