You can use np.ufunc.reduce with multiple axis to get as array as you want.
(first find max on axis=1 from X1 , X2 then find max on axis=0 from result.)
np.maximum.reduce([X1, X2], axis=(1,0))
# array([4633.70349825])
np.minimum.reduce([X1, X2], axis=(1,0))
# array([319.09009796])
Or try this to get as value:
>>> np.max((X1,X2))
4633.70349825
>>> np.min((X1,X2))
319.09009796
Or try this to get as array:
>>> max(max(X1), max(X2))
array([4633.70349825])
>>> min(min(X1), min(X2))
array([319.09009796])
Answer from Mahdi F. on Stack OverflowYou can use np.ufunc.reduce with multiple axis to get as array as you want.
(first find max on axis=1 from X1 , X2 then find max on axis=0 from result.)
np.maximum.reduce([X1, X2], axis=(1,0))
# array([4633.70349825])
np.minimum.reduce([X1, X2], axis=(1,0))
# array([319.09009796])
Or try this to get as value:
>>> np.max((X1,X2))
4633.70349825
>>> np.min((X1,X2))
319.09009796
Or try this to get as array:
>>> max(max(X1), max(X2))
array([4633.70349825])
>>> min(min(X1), min(X2))
array([319.09009796])
You need to wrap the arrays in a array-like object (list, tuple). See below:
ma = np.max([X1, X2])
mi = np.min([X1, X2])
print(ma)
print(mi)
Output
4633.70349825
319.09009796
By default both max and min will flatten the input, from the documentation:
axis None or int or tuple of ints, optional Axis or axes along which to operate. By default, flattened input is used.
With this setup:
>>> A = np.array([0,1,2])
>>> B = np.array([1,0,3])
>>> C = np.array([3,0,4])
You can either do:
>>> np.maximum.reduce([A,B,C])
array([3, 1, 4])
Or:
>>> np.vstack([A,B,C]).max(axis=0)
array([3, 1, 4])
I would go with the first option.
You can use reduce. It repeatedly applies a binary function to a list of values...
For A, B and C given in question...
np.maximum.reduce([A,B,C])
array([3,1,4])
It first computes the np.maximum of A and B and then computes the np.maximum of (np.maximum of A and B) and C.
np.max is just an alias for np.amax. This function only works on a single input array and finds the value of maximum element in that entire array (returning a scalar). Alternatively, it takes an axis argument and will find the maximum value along an axis of the input array (returning a new array).
>>> a = np.array([[0, 1, 6],
[2, 4, 1]])
>>> np.max(a)
6
>>> np.max(a, axis=0) # max of each column
array([2, 4, 6])
The default behaviour of np.maximum is to take two arrays and compute their element-wise maximum. Here, 'compatible' means that one array can be broadcast to the other. For example:
>>> b = np.array([3, 6, 1])
>>> c = np.array([4, 2, 9])
>>> np.maximum(b, c)
array([4, 6, 9])
But np.maximum is also a universal function which means that it has other features and methods which come in useful when working with multidimensional arrays. For example you can compute the cumulative maximum over an array (or a particular axis of the array):
>>> d = np.array([2, 0, 3, -4, -2, 7, 9])
>>> np.maximum.accumulate(d)
array([2, 2, 3, 3, 3, 7, 9])
This is not possible with np.max.
You can make np.maximum imitate np.max to a certain extent when using np.maximum.reduce:
>>> np.maximum.reduce(d)
9
>>> np.max(d)
9
Basic testing suggests the two approaches are comparable in performance; and they should be, as np.max() actually calls np.maximum.reduce to do the computation.
You've already stated why np.maximum is different - it returns an array that is the element-wise maximum between two arrays.
As for np.amax and np.max: they both call the same function - np.max is just an alias for np.amax, and they compute the maximum of all elements in an array, or along an axis of an array.
In [1]: import numpy as np
In [2]: np.amax
Out[2]: <function numpy.core.fromnumeric.amax>
In [3]: np.max
Out[3]: <function numpy.core.fromnumeric.amax>