How do paired positions become a grid of occupancy counts?
histogram2d bins paired x and y coordinates. The first dimension of its result indexes x bins.
numpy.histogram2d in practice
Samples (0,1) and (1,1) land in different x bins but the same y bin. Image displays usually put the vertical axis on rows, so check the orientation before plotting.
import numpy as np
np.histogram2d([0,1],[1,1],bins=([-0.5,0.5,1.5],[-0.5,0.5,1.5]))[0]Result [[0.0, 1.0], [0.0, 1.0]]
中文
如何把二维位置计入占用网格?
histogram2d 将 x、y 坐标对分到两个方向的区间,输出第一轴对应 x 区间。
numpy.histogram2d 算例
样点 (0,1) 与 (1,1) 各落在不同 x 格、相同 y 格。显示图像时通常以行代表纵轴,应核对是否要转置。
import numpy as np
np.histogram2d([0,1],[1,1],bins=([-0.5,0.5,1.5],[-0.5,0.5,1.5]))[0]结果 [[0.0, 1.0], [0.0, 1.0]]