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
在每次迭代中,我用linspace
函数构造centersX
和{centers
的2x1细胞数组中。H是一个nbins X nbins X n结构。在每次迭代中,我用hist3中的数据填充H的nbins X nbins片段。在
我在找Python的等价物。传递numpy.histogram2d
的参数时遇到问题:
我得到以下错误:
Traceback (most recent call last):
line 714, in histogramdd
N, D = sample.shape
AttributeError: 'list' object has no attribute 'shape'
During handling of the above exception, another 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: too many values to unpack (expected 2)
由于Python没有单元数组,所以我将centers改为一个数组,其中centers[0] = centersX
和{
编辑:
我也尝试过H[:,:,i] = numpy.histogram2d(xData,yData, bins=(centersX,centersY))
将组合步骤剪切成{
目前没有回答
相关问题 更多 >
编程相关推荐