# Efficient division for two probilities

**URL:** https://discourse.julialang.org/t/efficient-division-for-two-probilities/96579
**Category:** New to Julia
**Tags:** question
**Created:** [March 24, 2023, 9:34pm UTC](https://discourse.julialang.org/t/efficient-division-for-two-probilities/96579 "2023-03-24T21:34:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![X\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/x_chen/32/47565_2.png) [@X\_Chen](https://discourse.julialang.org/u/X_Chen)
#### Post date: [March 24, 2023, 9:34pm UTC](https://discourse.julialang.org/t/efficient-division-for-two-probilities/96579/1 "2023-03-24T21:34:59Z")

</div>

Hi everyone,

I have a very large dataframe (1 million observations) that I need to do calculation for two probabilities (p1 and p2): log(p1/(1-p2)).  
And my code is:  
log.(p1)/ (-p2.+1)  
I think my code is so inefficient that it will run out of memory. So I am wondering if there is any way to get rid of the dot operator?  
Thanks a lot!

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [March 24, 2023, 9:50pm UTC](https://discourse.julialang.org/t/efficient-division-for-two-probilities/96579/2 "2023-03-24T21:50:13Z")

</div>

1 million observations shouldn’t be large for a reasonably new laptop. It seems that you are missing a dot and your parens are off, shouldn’t it be `log.(p1./ (1 .- p2)) `?

---

<div class="post-metadata">

### Author: ![blackeneth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blackeneth/32/10353_2.png) [@blackeneth](https://discourse.julialang.org/u/blackeneth)
#### Post date: [March 24, 2023, 10:27pm UTC](https://discourse.julialang.org/t/efficient-division-for-two-probilities/96579/3 "2023-03-24T22:27:43Z")

</div>

If you p1 can be zero, or p2 can be 1, and you don’t want +Inf and -Inf in the results, one trick is to add 0.000001 to the top and bottom of the ration. Then the max and min values will be +13.8 and -13.8.

One million rows will be no problem for this calculation. Begin to worry between 100 - 300 million rows.

---

<div class="post-metadata">

### Author: ![X\_Chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/x_chen/32/47565_2.png) [@X\_Chen](https://discourse.julialang.org/u/X_Chen)
#### Post date: [March 24, 2023, 11:04pm UTC](https://discourse.julialang.org/t/efficient-division-for-two-probilities/96579/5 "2023-03-24T23:04:32Z")

</div>

Thank you so much! That solves the problem.
