Numpy 的 maximum()
方法将两个数组作为输入,并执行逐元素比较以返回包含每对中较大值的新 Numpy 数组。
参数
1. x1
| array-like
第一个输入数组。
2. x2
| array-like
第二个输入数组。
如果x1
和x2
的形状不匹配,则数组必须能够广播到通用形状。请参阅下面的示例以进行说明。
返回值
一个 Numpy 数组,保存成对比较的最大值。
例子
当形状匹配时
x = np.array([2,3,7])
y = np.array([1,5,6])
z = np.maximum(x,y)
z
array([2, 5, 7])
在这里,我们进行三个比较; 2 > 1
、3 < 5
和 7 > 6
。最大值为 2
、 5
和 7
。
当形状不匹配时
我们现在检查两个数组的形状不匹配的情况。
x = np.array([3,2])
y = np.array([[1,4],[5,6]])
z = np.maximum(x,y)
z
array([[3, 4],
[5, 6]])
NaNs之间的比较
当数字与 NaN
进行比较时,返回 NaN
:
x = np.array([np.NaN,2])
y = np.array([1,4])
z = np.maximum(x,y)
z
array([nan, 4.])
相关用法
- Python max方法用法及代码示例
- Python Tkinter maxsize()用法及代码示例
- Python max()用法及代码示例
- Python string max()用法及代码示例
- Python max() and min()用法及代码示例
- Python matplotlib.patheffects.withTickedStroke用法及代码示例
- Python matplotlib.axes.Axes.step用法及代码示例
- Python matplotlib.texmanager.TexManager.get_rgba用法及代码示例
- Python matplotlib.backend_bases.MouseEvent用法及代码示例
- Python matplotlib.collections.RegularPolyCollection.set_hatch用法及代码示例
- Python numpy ma.MaskedArray.view用法及代码示例
- Python matplotlib.patches.Rectangle用法及代码示例
- Python matplotlib._api.deprecation.deprecated用法及代码示例
- Python matplotlib._api.select_matching_signature用法及代码示例
- Python matplotlib.figure.Figure.align_xlabels用法及代码示例
- Python matplotlib.pyplot.step()用法及代码示例
- Python matplotlib.figure.SubFigure.add_subplot用法及代码示例
- Python matplotlib.collections.BrokenBarHCollection.set_hatch用法及代码示例
- Python math.cos()用法及代码示例
- Python math.cosh()用法及代码示例
- Python matplotlib.collections.PolyCollection.sticky_edges用法及代码示例
- Python matplotlib.axes.Axes.barbs用法及代码示例
- Python matplotlib.textpath.TextToPath.get_text_path用法及代码示例
- Python math.acosh()用法及代码示例
- Python main()用法及代码示例
注:本文由纯净天空筛选整理自Isshin Inada大神的英文原创作品 NumPy | maximum method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。