python np 数组中值的规范化出错了?

normalization of values in python np array gone wrong?

我有一个形状为 (3000, 9) 的浮点数矩阵。 在 1 行中,有 1 个''simulation''。 跨列,对于固定行,有''simulation''的内容。

我希望对于每个模拟,将前 8 列归一化为前 8 列的总和。 也就是说,第一列的条目(对于一个固定行)变成之前的内容,超过前 8 列的总和(对于同一固定行)。

一项微不足道的任务,但我从一个漂亮、正确的图表(非标准化)中得到了一些在使用 plt.scatter 绘图时完全不真实的东西。

每行的最后一列是我们将用于 x 轴绘制前 8 列(y 值)的内容。 因此,对于 x 的 1 个固定值,一行将代表 8 个数据点。

非标准化图: https://ibb.co/Msr8RVB

归一化图: https://ibb.co/tJp7bZn

数据集: 非标准化:https://easyupload.io/oat9kq

我的代码:

import numpy as np
from matplotlib import pyplot as plt


non_norm = np.loadtxt("integration_results_3000samples_10_20_10_25_Wcm2_BenSimulationFromSlack.txt")

plt.figure()
for i in range(non_norm.shape[1]-1):
    plt.scatter(non_norm[:, -1], non_norm[:, i], label="c_{}".format(i+47))
plt.xscale("log")
plt.savefig("non-norm_Ben3000samples.pdf", bbox_inches='tight')

norm = np.empty( (non_norm.shape[0], non_norm.shape[1]) )
norm[:, -1] = non_norm[:, -1]

for i in range(norm.shape[1]-1):
    for j in range(norm.shape[0]):
        norm[j, i] = np.true_divide(non_norm[j, i] , np.sum(non_norm[j, :-1]))

plt.figure()
for i in range(norm.shape[1]-1):
    plt.scatter(norm[:, -1], norm[:, i], label="c_{}".format(i+47))
plt.xscale("log")
plt.savefig("norm_Ben3000samples.pdf", bbox_inches='tight')

你知道哪里出了问题吗? 谢谢

当您规范化只有一个值和 7 个零的行时,该值变为 1 而该行的其余部分为 0?这可能就是你的情节搞砸的原因。

例如,第一列的图在归一化前后如下所示: