Change language

sciPy stats.binned_statistic_dd () function | python

stats.binned_statistic_dd (arr, values, statistic = & # 39; mean & # 39 ;, bins = 10, range = None) calculates statistic value for given 2D data. 
It works in a similar way to histogram2d. Since the histogram function makes bins and counts no. points in each basket; this function calculates the sum, average, mean -median-mode-in-python-without-libraries/">median, count, or other statistics of values ​​for each bin.

Parameters:
arr: [array_like] Data to histogram passed as (N, D) array
values: [array_like] on which stats to be calculated.
statistics: Statistics to compute { mean , count, mean -median-mode-in-python-without-libraries/">median, sum, function}. Default is mean .
bin: [int or scalars] If bins is an int, it defines the number of equal-width bins in the given range (10, by default). If bins is a sequence, it defines the bin edges.
range: (float, float) Lower and upper range of the bins and if not provided, range is from x.max () to x.min ().

Results: Statistics value for each bin; bin edges; bin number.

Code # 1:

# stats.binned_statistic_dd () method

import numpy as np

from scipy import stats

 

x = np.ones ( 10 )

y = np.ones ( 10 )

 

print ( " x: " , x) 

print ( "y:" , y)

 

print ( " binned_statistic_2d for count: "

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

Output:

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))

Code # 2:

# import 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 ( " binned_statistic_2d for count: "

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

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

Output:

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))

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically