sciPy stats.binned_statistic_2d()関数| Python

| | | | | | | | | | | |

stats.binned_statistic_2d(arr1、arr2、values、statistic =' mean&#39 ;, bins = 10、range = None)は統計を計算します与えられた2次元データの値。
histogram2dと同じように機能します。ヒストグラム関数はビンを作成し、カウントしないためです。各バスケットのポイント。この関数は、各ビンの値の合計、平均、中央値、カウント、またはその他の統計を計算します。

パラメーター:
arr1 :[array_like]入力配列を最初の次元に沿ってビニングします。
arr2:[array_like]入力配列を2番目の次元に沿ってビニングします。
値:[array_like]統計を計算します。
統計: {平均、カウント、中央値、合計、関数}を計算するための統計。デフォルトは平均です。
bin:[intまたはscalars]binsがintの場合、指定された範囲(デフォルトでは10)の等幅ビンの数を定義します。ビンがシーケンスの場合、ビンのエッジを定義します。
範囲:(float、float)ビンの下限と上限の範囲。指定されていない場合、範囲はx.max()からx.min()。

結果:各ビンの統計値。 1次元と2次元に沿ったビンのエッジ。ビン番号。

コード#1:


#統計。 binned_statistic_2d()メソッド

import numpy as np

from scipy import stats


x = np.random。 rand( 10

y = np.random.rand( 10


z = np.arange( 10


印刷 "x:" 、x)

print "y:" 、y)

print " z: " 、z)


#amount

print "binned_statistic_2d for count:"

stats.binned_statistic_2d(x、y、値、Äã‚Äã = z、

統計 = `count` 、bins = [ 5 5 ]))

出力:

x:
[0.31218238 0.86791445 0.42763346 0.79798587 0.91361299 0.09005856
0.54419846 0.18973948 0.67016378 0.8083121]

y:
[0.35959238 0.69265819 0.18751529 0.98863414 0.97810927 0.24054104
0.76764562 0.60635485 0.61551806 0.63884672]

1:2 3 4 5 6 7 8 9]

binned_statistic_2d for count:BinnedStatistic2dResult(statistic = array([[1.、0.、1.、0.、0。]、
[0。、1.、0.、0.、0。 ]、
[1.、0.、0.、1.、0。]、
[0.、0.、1.、0.、0。]、
[0.、0 。、1.、1.、2。]])、x_edge = array([0.09005856、0.25476945、0.41948033、0.58419122、0.74890211、
0.91361299])、y_edg e = array([0.18751529、0.34773906、0.50796283、0.6681866、 0.82841037、
0.98863414])、binnumber = array([16、39、22、40、40、 8、25、10、31、38]、dtype = int64))

コード#2:


#stats.binned_statistic_2d()メソッド

import numpy as np

from scipy import stats


x = np.random.rand( 10

y = np.random。 rand( 10

z = np.arange( 10


#greedy

print "binned_statistic_2d for mean:"

stats.binned_statistic_2d(x、y、values、Äã‚Äã = z 、

統計 = `mean` 、bins = [ 5 5 ]))

出力:

binned_statistic_2d for mean:BinnedStatistic2dResult(statistic = array([[5.、nan、7.、nan、nan]、
[nan、0.、nan、nan、nan]、
[2.、nan、nan、6.、nan]、
[nan、nan、8.、nan、nan]、
[nan、nan、9.、1.、3.5]] )、x_edge = array([0.09005856、0.25476945、0.41948033、0.58419122、0.74890211、
0.91361299])、y_edge = array([0.18751529、0.34773906、0.50796283、0.6681866、0.82841037、
0.98863414])、binnumber = array( [16、39、22、40、40、8、25、10、31、38]、dtype = int64))