Python equivalent of Matlab's hist3 -
for i=1:n centersx(:,i)=linspace(min(xdata)+dx/2,max(xdata)-dx/2,nbins)'; centersy(:,i)=linspace(min(ydata)+dy/2,max(phase)-dy/2,nbins)'; centers = {centersx(:,i),centersy(:,i)}; h(:,:,i) = hist3([xdata ydata],centers); end
in each iteration, construct centersx
, centersy
linspace
function. store them in 2x1 cell array called centers
. h nbins x nbins x n struct. in each iteration fill nbins x nbins slice of h data hist3.
i'm looking python equivalent. i'm having trouble passing arguments numpy.histogram2d
:
h[:,:,i] = numpy.histogram2d(xdata,ydata,centers)
i following error:
traceback (most recent call last): line 714, in histogramdd n, d = sample.shape attributeerror: 'list' object has no attribute 'shape' during handling of above exception, exception occurred: traceback (most recent call last): line 36, in <module> h[:,:,i] = numpy.histogram2d(xdata, ydata, centers) line 714, in histogram2d hist, edges = histogramdd([x, y], bins, range, normed, weights) line 718, in histogramdd n, d = sample.shape valueerror: many values unpack (expected 2)
since python doesn't have cell arrays, changed centers array of arrays centers[0] = centersx
, centers[1] = centersy
. need change such that assuming data same between matlab , python outputs match?
edit: have tried h[:,:,i] = numpy.histogram2d(xdata,ydata, bins=(centersx,centersy))
cutout combining step centers
no luck.
Comments
Post a Comment