Hướng dẫn weighted median python numpy
What we can do, if i understood your problem correctly. Is to sum up the observations, dividing by 2 would give us the observation number corresponding to the median. From there we need to figure out what observation this number was. One trick here, is to calculate the observation sums with np.cumsum. Which gives us a running cumulative sum. Example: So all we need to do, is figure out the index of where the median (5) will fit. The code to do it like so:
Output will be:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
|