Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Let a be a numpy array of length n. Does the statement a == max(a) calculate the expression max(a) n-times or just one?
numpy.amax
max
It computes max(a) once, then it compares the (scalar) result against each (scalar) element in a, and creates a bool-array for the result.
max(a)
Add a comment
It only evaluates max once. You could test this yourself by writing your own function:
def mymax(x): print("Calling mymax.") return max(x)
Then try
a == mymax(a)
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
numpy.amaxrather than plain Pythonmax.