import numpy as np
from scipy.stats import truncnorm, norm
a_s = np.random.uniform(0, 1, size=100)
b_s = a_s + 0.2
cdf_start = norm.cdf(a_s)
cdf_stop = norm.cdf(b_s)
cdf_samples = np.random.uniform(0, 1, size=(100, 100))
cdf_samples *= (cdf_stop - cdf_start)[:, (None)]
cdf_samples += cdf_start[:, (None)]
truncnorm_samples = norm.ppf(cdf_samples)
Vectorised code for sampling from truncated normal distributions with different intervals