Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
61 views
in Technique[技术] by (71.8m points)

python - numpy.max or max ? Which one is faster?

In python, which one is faster ?

numpy.max(), numpy.min()

or

max(), min()

My list/array length varies from 2 to 600. Which one should I use to save some run time ?

question from:https://stackoverflow.com/questions/10943088/numpy-max-or-max-which-one-is-faster

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Well from my timings it follows if you already have numpy array a you should use a.max (the source tells it's the same as np.max if a.max available). But if you have built-in list then most of the time takes converting it into np.ndarray => that's why max is better in your timings.

In essense: if np.ndarray then a.max, if list and no need for all the machinery of np.ndarray then standard max.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...