我有一个时间戳数组,矩阵 X 的第二列中的每一行都会增加。我计算时间戳的平均值,它大于最大值。我正在使用 numpy memmap 进行存储。为什么会这样?
>>> self.X[:,1]
memmap([ 1.45160858e+09, 1.45160858e+09, 1.45160858e+09, ...,
1.45997146e+09, 1.45997683e+09, 1.45997939e+09], dtype=float32)
>>> np.mean(self.X[:,1])
1.4642646e+09
>>> np.max(self.X[:,1])
memmap(1459979392.0, dtype=float32)
>>> np.average(self.X[:,1])
1.4642646e+09
>>> self.X[:,1].shape
(873608,)
>>> np.sum(self.X[:,1])
memmap(1279193195216896.0, dtype=float32)
>>> np.sum(self.X[:,1]) / self.X[:,1].shape[0]
memmap(1464264515.9120522)
编辑:我在这里上传了 memmap 文件。http://www.filedropper.com/x_2这就是我加载它的方式。
filepath = ...
shape = (875422, 23)
X = np.memmap(filepath, dtype="float32", mode="r", shape=shape)
# I preprocess X by removing rows with all 0s
# note this step doesn't affect the problem
to_remove = np.where(np.all(X == 0, axis=1))[0]
X = np.delete(X, to_remove, axis=0)