以下将当前直方图附加到之前的直方图:
# prepare result array
histograms = np.array([])
for i in np.arange(1999):
temp_histogram, bin_edges= np.histogram([critters_intervals[i, :]], bins=np.arange(101))
# append latest histogram to the previous ones
np.concatenate((histograms, temp_histogram))
如果您想对直方图求和/累加,可以执行以下操作:
accumulated_histogram = np.zeros(100)
for i in np.arange(1999):
temp_histogram, bin_edges= np.histogram([critters_intervals[i, :]], bins=np.arange(101))
# add latest histogram to the previous counts
accumulated_histogram += temp_histogram
编辑(回复评论):
如果您想将所有直方图存储在一个二维数组中,您有以下选择:
1.预分配一个二维数组并随后填充它:
all_histograms = np.zeros((1999, 100))
for i in np.arange(1999):
all_histograms[:,i], bin_edges= np.histogram([critters_intervals[i, :]], bins=np.arange(101))
2.生成直方图后将其堆叠
# initialize array with first histogram
all_histograms, all_bin_edges = np.histogram([critters_intervals[0, :]], bins=np.arange(101))
for i in np.arange(1999):
temp_histogram, bin_edges= np.histogram([critters_intervals[i, :]], bins=np.arange(101))
all_histograms = np.vstack((all_histograms, temp_histogram))