Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

Create bimodal distribution from two uniform distribution using Numpy

$
0
0

I am trying to reproduce the bimodalSample function of this blog in Python.

My attempt:

import numpy as npdef bimodal_pdf(distance: float, weight: float) -> np.ndarray:    r = np.random.rand()    if r < weight:        return np.random.normal(r) * (1 - distance)    else:        return np.random.normal(r) * (1 - distance) + distancen_samples = 100000distance = 0.7weight = 0.5pdf = np.array([    bimodal_pdf(distance=distance, weight=weight) for s in range(n_samples)])

However, I am getting values below zero and above 1. What's wrong with my implementation?Thanks


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>