0

Because math.log does not support array, I'd like to complete log calculation in numpy.log instead of math.log

However, there are log10(),log2() in numpy. How do I calculate more general log like log5(6) in numpy? Please don't use log(6)/log(5)...

Thanks a lot!

Bin
  • 209
  • 1
  • 3
  • 8
  • Why do you not want to use `np.log(6)/np.log(5)`, that's the definition of the log base change rule. If you're asking if there is some `logn(num)` function in numpy, there is not. – user3483203 Aug 07 '18 at 06:27
  • 1
    Math: `log[b](a) = log[x](a) / log[x](b)`, for any `x` (say, `10`, or `2`, or `e` - doesn't really matter which). "Please don't use log(6)/log(5)" = "How do I eat soup? Please don't suggest spoon". – Amadan Aug 07 '18 at 06:28
  • It's not built in, so if you ask us not to use the only sensible workaround, you're not likely to get any answers :) – Thomas Aug 07 '18 at 06:29
  • You can either do arbitrary bases with the `math` module, or you can do it manually with the log base change rule using `numpy`. You could also write your own functions that suit your needs. Those are pretty much your only options. – mypetlion Aug 07 '18 at 06:30
  • The `math.log` docs say it uses the log division method when given a base. – hpaulj Aug 07 '18 at 06:41
  • @Amadan Of course log(6)/log(5) is mathematically right. I want a direct and simple approach... – Bin Aug 07 '18 at 07:07
  • That *is* the most direct and simple approach. – Amadan Aug 07 '18 at 07:33
  • [Here's proof](https://github.com/python/cpython/blob/9c18b1ae527346bc178250ad1ca07bffdacde5dd/Modules/mathmodule.c#L1957) what @hpaulj said: if you write `math.log(6, 5)`, it is actually calculated as `log(6)/log(5)`. – Amadan Aug 07 '18 at 07:44

0 Answers0