参考链接: numpy.maximum
参考链接: numpy.minimum
这两个函数的功能大体分别是在两个多维数组中逐元素求最大值和最小值
实验1: numpy.maximum()函数
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import numpy as np
>>> np.maximum([2, 3, 4], [1, 5, 2])
array([2, 5, 4])
>>>
>>> np.maximum(np.eye(2), [0.5, 2]) # broadcasting
array([[1. , 2. ],
[0.5, 2. ]])
>>>
>>>
>>> np.maximum([np.nan, 0, np.nan], [0, np.nan, np.nan])
array([nan, nan, nan])
>>>
>>> np.maximum(np.Inf, 1)
inf
>>>
>>>
>>> np.random.seed(20200910)
>>> a = np.random.randint(100,200,(3,4))
>>> b = np.random.randint(100,200,(3,4))
>>> a
array([[148, 110, 129, 184],
[120, 148, 109, 122],
[112, 106, 111, 135]])
>>> b
array([[124, 107, 185, 199],
[188, 184, 142, 142],
[148, 112, 158, 115]])
>>> np.maximum(a, b)
array([[148, 110, 185, 199],
[188, 184, 142, 142],
[148, 112, 158, 135]])
>>>
>>> np.maximum(a, 2020)
array([[2020, 2020, 2020, 2020],
[2020, 2020, 2020, 2020],
[2020, 2020, 2020, 2020]])
>>> np.maximum(20200910, b)
array([[20200910, 20200910, 20200910, 20200910],
[20200910, 20200910, 20200910, 20200910],
[20200910, 20200910, 20200910, 20200910]])
>>>
>>>
实验2: numpy.minimum()函数
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import numpy as np
>>> np.minimum([2, 3, 4], [1, 5, 2])
array([1, 3, 2])
>>> np.minimum(np.eye(2), [0.5, 2]) # broadcasting
array([[0.5, 0. ],
[0. , 1. ]])
>>> np.minimum([np.nan, 0, np.nan],[0, np.nan, np.nan])
array([nan, nan, nan])
>>> np.minimum(-np.Inf, 1)
-inf
>>>
>>>
>>>
>>> np.random.seed(20200910)
>>> a = np.random.randint(100,200,(3,4))
>>> b = np.random.randint(100,200,(3,4))
>>> a
array([[148, 110, 129, 184],
[120, 148, 109, 122],
[112, 106, 111, 135]])
>>> b
array([[124, 107, 185, 199],
[188, 184, 142, 142],
[148, 112, 158, 115]])
>>> np.minimum(a, b)
array([[124, 107, 129, 184],
[120, 148, 109, 122],
[112, 106, 111, 115]])
>>> np.minimum(a, 91)
array([[91, 91, 91, 91],
[91, 91, 91, 91],
[91, 91, 91, 91]])
>>> np.minimum(20, b)
array([[20, 20, 20, 20],
[20, 20, 20, 20],
[20, 20, 20, 20]])
>>>
>>>
>>>