5

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] ])

4
  • 1
    What's a here? And is this Python 2.x or 3.x (map() is not the same in both)? Commented Aug 27, 2013 at 15:21
  • have you tried import speed? Seriously though, what does a look like and what is the required output? Commented Aug 27, 2013 at 15:21
  • is a a numpy.ndarray? (you can check this doing type(a))... Commented Aug 27, 2013 at 15:24
  • What is your expected output? Commented Aug 27, 2013 at 15:32

1 Answer 1

6

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])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.