如题,使用np.sum函数求和时出现了一些问题,代码如下:
label_column = jisuan_train_time[:,:,0]
column_sums = np.sum(label_column, axis=0)
print(column_sums) # 打印结果数组
然后输出的不是我想要的和,而是:
['1010101100111110110111011111111111111010101111010001001101011101111111111110101110101110010001001111111101111011101101011111111111010101111111111111111111101111111110101110110011100101111111001110111011101110011101111110010010101111111111111111111110111011011111110111010001111011010001111111100111111101110110010011011111011101100111110110101111001111101111111111011010011111111011011100111101100110111001111111111111111110111011001101110001111011111010111111111101010111111110011111101100111111111111111101100111001110111101111111111001111111111111101111101011]
最后我找到了原因,我的label_column中存放的数据是布尔类型的,把这个变量转变为int就可以了,修改如下
label_column = label_column.astype(int)
column_sums = np.sum(label_column, axis=0)
print(column_sums) # 打印结果数组