python - Histogram in N dimensions with numpy -



python - Histogram in N dimensions with numpy -

i'm trying generate 2 2d histograms using numpy.histogramdd (i'm aware of histogram2d, need 1 scalability n dimensions eventually)

both histograms should utilize same range, define before obtaining them.

the issue can't code work, either valueerror: many values unpack or valueerror: sequence large; must smaller 32 error using different configurations.

here's mwe:

import numpy np def rand_data(n): homecoming np.random.uniform(low=1., high=2000., size=(n,)) # random 2d data. n = 100 p = [rand_data(n), rand_data(n)] q = [rand_data(n), rand_data(n)] # number of bins. b = np.sqrt(len(p[0])) * 2 # max , min values x , y x_min = np.sort(np.minimum(p[0], q[0]))[0] x_max = np.sort(np.minimum(p[0], q[0]))[-1] y_min = np.sort(np.minimum(p[1], q[1]))[0] y_max = np.sort(np.minimum(p[1], q[1]))[-1] # range histograms. rang = [np.linspace(x_min, x_max, b), np.linspace(y_min, y_max, b)] # histograms d_1 = np.histogramdd(zip(*[p[0], p[1]]), range=rang)[0] d_2 = np.histogramdd(zip(*[q[0], q[1]]), range=rang)[0]

what doing wrong?

the next code should work you. there 2 issues: edges of bins passed bins argument, not range argument. besides, passing list of tuples not seem work. if convert tuples numpy array , pass array should work expected.

this code works me:

import numpy np def rand_data(n): homecoming np.random.uniform(low=1., high=2000., size=(n,)) # random 2d data. n = 100 p = [rand_data(n), rand_data(n)] q = [rand_data(n), rand_data(n)] # number of bins. b = np.sqrt(len(p[0])) * 2 # max , min values x , y x_min = np.sort(np.minimum(p[0], q[0]))[0] x_max = np.sort(np.minimum(p[0], q[0]))[-1] y_min = np.sort(np.minimum(p[1], q[1]))[0] y_max = np.sort(np.minimum(p[1], q[1]))[-1] # range histograms. rang = [np.linspace(x_min, x_max, b), np.linspace(y_min, y_max, b)] # histograms sample1 = np.array(list(zip(*[p[0], p[1]]))) sample2 = np.array(list(zip(*[q[0], q[1]]))) d_1 = np.histogramdd(sample1, bins=rang)[0] d_2 = np.histogramdd(sample2, bins=rang)[0]

python arrays numpy histogram

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -