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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。