Python faster way to take logarithm of N-dimensional array
The numpy log function is implemented in C and optimised for handling arrays, so although you may be able to scrape a bit of overhead off by writing your own custom log function in a lower-level language, this will still remain the bottleneck. If you want to see a big speed increase, you'll need to implement your algorithm differently.
Is it really necessary to take the log of all these elements? You mention that each dimension can have 100 samples, do you plan on averaging these samples? If so you can reduce the number of logarithms you need to compute by using the fact that log(a) + log(b) = log(ab), and so the average [log(a0) + log(a1) + ... + log(aN)]/(a0 + a1 + ... + aN) is the same as log(a0*a1*...*aN)/(a0 + a1 + ... + aN).
My question is trivial, nevertheless I need your help. It's not a problem to take a np.log(x) of an array. But in my case this array could be N-dimensional/Tensor (N=2..1024 and 100 samples in each dimension). 
For N=4 calculation of element-wise np.log(x) takes 10 seconds. I need to take this log(x) in a cost function for optimization, thus, all process of optimization takes roughly 2 hours.
So, the question is how this log(x) can be implemented in faster way for N-dimensional arrays. Is it really possible?  
Thanks in advance.