Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need faster python code for calculating sample entropy

This is the problem I have faced when I am writing python code for sample entropy.

map(max, abs(a[i]-a) ) is very slow.

Is there any other function perform better than map() ?

Where a is ndarray that looks like np.array([ [1,2,3,4,5],[2,3,4,5,6],[3,4,5,3,2] ])

like image 637
Xin Li Avatar asked Aug 27 '13 15:08

Xin Li


1 Answers

Use the vectorized max

>>> map(max, abs(a[2]-a) )
[3, 4, 0]
>>> np.abs(a[2] - a).max(axis=1)
array([3, 4, 0])
like image 164
Viktor Kerkez Avatar answered Sep 30 '22 18:09

Viktor Kerkez