python scipy stats_Python Scipy stats.binned_statistic_dd()用法及代码示例

stats.binned_statistic_dd(arr, values, statistic='mean', bins=10, range=None)函数为给定的二维数据计算合并的统计值。

它的工作原理类似于histogram2d。直方图功能使箱子计数为零。每个箱子中的点数;此函数计算每个仓的值的总和,均值,中位数,计数或其他统计量。

参数:

arr :[数组]直方图的数据作为(N,D)数组传递

values :[数组]要计算哪些统计信息。

statistics:统计以计算{平均值,计数,中位数,和,函数}。默认为平均值。

bins:[int或标量]如果bins是一个int,则它定义给定范围内的equal-width bins的数量(默认为10)。如果bin是序列,则它定义bin的边。

range:(浮动,浮动)箱子的上下范围,如果未提供,则范围为x.max()至x.min()。

Results:每个仓的统计值;箱边箱号。

代码1:

# stats.binned_statistic_dd() method

import numpy as np

from scipy import stats

x = np.ones(10)

y = np.ones(10)

print ("x:\n", x)

print ("\ny:\n", y)

print ("\nbinned_statistic_2d for count:",

stats.binned_statistic_dd([x, y], None, 'count', bins = 3))

输出:

x:

[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]

y:

[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]

binned_statistic_2d for count: BinnedStatisticddResult(statistic=array([[ 0., 0., 0.],

[ 0., 10., 0.],

[ 0., 0., 0.]]), bin_edges=[array([0.5, 0.83333333, 1.16666667, 1.5 ]),

array([0.5, 0.83333333, 1.16666667, 1.5 ])],

binnumber=array([12, 12, 12, 12, 12, 12, 12, 12, 12, 12], dtype=int64))

代码2:

# importing libraries

import numpy as np

from scipy import stats

# using np.ones for x and y

x = np.ones(10)

y = np.ones(10)

# Using binned_statistic_dd

print ("\nbinned_statistic_2d for count:",

stats.binned_statistic_dd([x, y], None,

'count', bins=3, range=[[2,3],[0,0.5]]))

输出:

binned_statistic_2d for count: BinnedStatisticddResult(statistic=array([[0., 0., 0.],

[0., 0., 0.],

[0., 0., 0.]]), bin_edges=[array([2., 2.33333333, 2.66666667, 3. ]),

array([0., 0.16666667, 0.33333333, 0.5 ])],

binnumber=array([4, 4, 4, 4, 4, 4, 4, 4, 4, 4], dtype=int64))

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值