import numpy as np
def nested_max(nestedList):
if not (isinstance(nestedList, list)):
return np.max(nestedList)
else:
return max([nested_max(a) for a in nestedList])
def nested_min(nestedList):
if not (isinstance(nestedList, list)):
return np.min(nestedList)
else:
return min([nested_min(a) for a in nestedList])
def total_max(*args):
return max([nested_max(a) for a in args])
def total_min(*args):
return min([nested_min(a) for a in args])
def total_range(*args):
return total_min(*args), total_max(*args)
This way one obtains for example:
>>> total_range(3.5,[4.5,1,[2,3], np.random.uniform(size=(5,6)),4],[2,-3])
(-3, 4.5)
This can be used in applications such as https://stackoverflow.com/a/42229589, where one could simply write:
mi, ma = total_range(dfz, xx)
instead of
mi = np.min((dfz.min(), xx.min()))
ma = np.max((dfz.max(), xx.max()))
to find the overall range of a combined plot.
Is there a nicer variant? E.g.: Supporting more types of tuples, sets, array and lists? Shorter code? Computationally more efficient?