About 238,000 results
Open links in new tab
  1. python - Find min, max, and average of a list - Stack Overflow

    I am having hard time to figure out how to find min from a list for example somelist = [1,12,2,53,23,6,17] how can I find min and max of this list with defining (def) a function I do not want to use

  2. python - Maximum and Minimum values for ints - Stack Overflow

    Sep 30, 2011 · If you want the max for array or list indices (equivalent to size_t in C/C++), you can use numpy: np.iinfo(np.intp).max This is same as sys.maxsize however advantage is that you don't need import sys just for this. If you want max for native int on the machine: np.iinfo(np.intc).max You can look at other available types in doc.

  3. max - How can I get the minimum and the maximum element of a …

    Jun 5, 2013 · If a have a list like: l = [1,2,3,4,5] and I want to have at the end min = 1 max = 5 WITHOUT min(l) and max(l).

  4. How to find min and max in python? - Stack Overflow

    Mar 3, 2015 · Maybe you could find the max and the min by searching into a number list: numbers=[1,2,6,5,3,6] max_num=numbers[0] min_num=numbers[0] for number in numbers: if number > max_num: max_num = number if number < min_num: min_num = number print max_num print min_num

  5. NumPy: function for simultaneous max () and min ()

    Jul 2, 2020 · numpy.amax() will find the max value in an array, and numpy.amin() does the same for the min value. If I want to find both max and min, I have to call both functions, which requires passing over t...

  6. Python max and min - Stack Overflow

    Dec 16, 2011 · int object is not iterable. There are 2 ways to overcome the problem. First either define a list as mentioned in the solutions earlier. The second option is compare the number entered by the user with the Max and Min variables defined while iterating in the While loop. –

  7. python max function using 'key' and lambda expression

    Aug 18, 2013 · max(iterable[, key=func]) -> value max(a, b, c, ...[, key=func]) -> value With a single iterable argument, return its largest item. With two or more arguments, return the largest argument. So, the key=func basically allows us to pass an optional argument key to the function on whose basis is the given iterator/arguments are sorted & the maximum ...

  8. How to override or perform min/max in python on your own class?

    Nov 14, 2018 · Not sure the best way to title this question, but how can I override or perform min(a, b) or max(a, b) on objects of a class i made? I can override the gt and lt like below but I would like to override the min or max so that I'll be able to use something like max(a, b, c ,d). The class will have multiple property as well, but I think 2 for this ...

  9. What do I use for a max-heap implementation in Python?

    Mar 23, 2010 · heap_max = [] # Creates an empty heap heappush_max(heap_max, item) # Pushes a new item on the heap item = heappop_max(heap_max) # Pops the largest item from the heap item = heap_max[0] # The largest item on the heap without popping it heapify_max(x) # Transforms the list into a heap, in-place, in linear time item = heapreplace_max(heap_max ...

  10. python - Find minimum and maximum values of a function - Stack …

    Sep 23, 2013 · Here is something which gives fairly close estimates (not exact). import math import random import sys def function(x, y): exp = (math.pow(x, 2) + math.pow(y, 2 ...

Refresh