Numpy中np.max(即np.amax)的用法


 

  1. >>> import numpy as np
  2. >>> help(np.max)
  • 當遇到一個不認識的函數,我們就需要查看一下幫助文檔

Numpy中np.max(即np.amax)的用法

  • np.maxnp.amax是同名函數
  1. amax(a, axis=None, out=None, keepdims=<no value>, initial=<no value>, where=<no value>)
  •   Return the maximum of an array or maximum along an axis.尋找矩陣最大和最小的元素
  •   axis=0 代表行 , axis=1 代表列
  •   若要返回每一列元素的最大值,需要在 axis=1 方向進行比較,則指定 axis=1
  •   若要返回每一行的最大值,在 axis=0 方向進行比較,則指定 axis=0

eg:一個簡單的例子

  1. import numpy as np
  2. np.random.seed(10)
  3. a = np.random.randint(1, 10, [5, 3])
  4. print(a)
  5. b = np.amax(a, axis=1) #找一個每行最大的
  6. print(b)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM