numpy.maximum()函数和numpy.minimum()函数的使用

参考链接: 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]])
>>> 
>>> 
>>> 
  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值