Reputation:
I have two datasets, like:
A=[ 1, 1.1, 1.2, 1.3, 1.1, 1.1, 1.2, 1.1, 1, 1, 1, 1, 1, 1, 1.1, 1.1, 1.1]
B=[1.4, 1.4, 1.3, 1.4, 1.4, 1.5, 1.4, 1.4, 1.3, 1.3, 1.3, 1.4, 1.3, 1.3, 1.2, 1.2, 1.4]
I want to divide the distributions of them, distributionA/distributionB, but I can not find any solution, because they are not list to divide them easily. Actually I want to calculate the supremium of distributionA/distributionB in python. I found a toolbox in R that does the same thing:
https://github.com/hoxo-m/densratio
but I want to do this in Python
Upvotes: 0
Views: 654
Reputation: 16184
that R package links to a Python module by the same author, I'd just use that! to install, just do the normal:
pip3 install -U densratio
then to use just follow the example in the docs:
from densratio import densratio
result = densratio(A, B)
print(result)
note though that this does crazy things with your data. I'd assume because because it's been rounded too much.
I'd start getting an estimate of the supremum by doing:
import numpy as np
x = np.linspace(-10, 10, 500)
y_hat = result.compute_density_ratio(x)
print(max(y_hat), x[np.argmax(y_hat)])
but you'd probably want to do lots of plots to make sure densratio
is doing the right thing, e.g. start with:
import matplotlib.pyplot as plt
plt.plot(x, y_hat)
note I've not seen this package before, somebody who's used this before might be able to help more
Upvotes: 0
Reputation: 88236
You can just map
with the truediv
operator:
from operator import truediv
list(map(truediv, A, B))
# [0.7142857142857143, 0.7857142857142858, 0.923076923076923, 0.9285714285714287...
Upvotes: 1
Reputation: 5632
This will divide every element in A by every element in B. If this is not what you need, please expand on your answer or post expected outcome.
res = [i / j for i, j in zip(A, B)]
Upvotes: 2