「NumPy」統計関数ptpメソッドで配列の要素範囲値を取得する

書式
numpy.ptp(a、axis = None、out = None、keepdims = <値なし>)
軸に沿った値の範囲(最大値から最小値まで)。
np.ptp(配列名, axis = 1)
np.ptp(配列名, axis = 0)
ptp関数で配列の要素の最大値と最小値の範囲(最大値-最小値)

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
a = np.array([[6,5,3],[9,3,3],[4,5,9]])
print ('配列の要素:')
print (a)
print ('\n')
print ('ptp()関数を呼び出す:')
print (np.ptp(a))
print ('\n')
print ('axis=1 ptp()関数の結果:')
print (np.ptp(a, axis = 1))
print ('\n')
print ('axis=0 ptp()関数の結果 :')
print (np.ptp(a, axis = 0))
import numpy as np a = np.array([[6,5,3],[9,3,3],[4,5,9]]) print ('配列の要素:') print (a) print ('\n') print ('ptp()関数を呼び出す:') print (np.ptp(a)) print ('\n') print ('axis=1 ptp()関数の結果:') print (np.ptp(a, axis = 1)) print ('\n') print ('axis=0 ptp()関数の結果 :') print (np.ptp(a, axis = 0))
import numpy as np 
 
a = np.array([[6,5,3],[9,3,3],[4,5,9]])  
print ('配列の要素:')
print (a)
print ('\n')
print ('ptp()関数を呼び出す:')
print (np.ptp(a))
print ('\n')
print ('axis=1 ptp()関数の結果:')
print (np.ptp(a, axis =  1))
print ('\n')
print ('axis=0 ptp()関数の結果 :')
print (np.ptp(a, axis =  0))

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
配列の要素:
[[6 5 3]
[9 3 3]
[4 5 9]]
ptp()関数を呼び出す:
6
axis=1 ptp() 関数の結果:
[3 6 5]
axis=0 ptp()関数の結果 :
[5 2 6]
配列の要素: [[6 5 3] [9 3 3] [4 5 9]] ptp()関数を呼び出す: 6 axis=1 ptp() 関数の結果: [3 6 5] axis=0 ptp()関数の結果 : [5 2 6]
配列の要素:
[[6 5 3]
 [9 3 3]
 [4 5 9]]


ptp()関数を呼び出す:
6


axis=1 ptp() 関数の結果:
[3 6 5]


axis=0 ptp()関数の結果 :
[5 2 6]

 

NumPy

Posted by arkgame