没有标识的Python零大小数组到ufunc.reduce

时间:2012-07-19 19:34:32

标签: python numpy

我正在尝试对存储在ndarray中的一些数据进行直方图。直方图是我在python程序中创建的一组分析的一部分。代码中无效的部分如下所示。

def histogram(self, iters):
    samples = T.MCMC(iters) #Returns an [iters,3,4] ndarray
    histAC = plt.figure(self.ip) #plt is matplotlib's pyplot
    self.ip+=1 #defined at the beginning of the class to start at 0
    for l in range(0,4):
        h = histAC.add_subplot(2,(iters+1)/2,l+1)
        for i in range(0,0.5*self.chan_num):
            intAvg = mean(samples[:,i,l])
            print intAvg
            for k in range(0,iters):
                samples[k,i,l]=samples[k,i,l]-intAvg
            print "Samples is ",samples
            h.hist(samples,bins=5000,range=[-6e-9,6e-9],histtype='step')     
            h.legend(loc='upper right')
            h.set_title("AC Pulse Integral Histograms: "+str(l))
    figname = 'ACHistograms.png'
    figpath = 'plot'+str(self.ip)
    print "Finished!"
    #plt.savefig(figpath + figname, format = 'png')

这给了我以下错误消息:

File "johnmcmc.py", line 257, in histogram
  h.hist(samples,bins=5000,range=[-6e-9,6e-9],histtype='step') #removed label=apdlabel      
File "/x/tsfit/local/lib/python2.6/site-packages/matplotlib/axes.py", line 7238, in hist
  ymin = np.amin(m[m!=0]) # filter out the 0 height bins
File "/x/tsfit/local/lib/python2.6/site-packages/numpy/core/fromnumeric.py", line 1829, in amin
  return amin(axis, out)
ValueError: zero-size array to ufunc.reduce without identity

我发现的唯一搜索结果是同一个两个对话的多个副本,我从中学到的唯一一点是python直方图不喜欢获取空数组,这就是为什么我添加了print语句的权利在线上,这让我很麻烦,以确保数组不为空。

之前是否有其他人遇到此错误?

0 个答案:

没有答案
相关问题