detail_num = 0 for id_0 in range(0, len(list_0)): path = os.path.join(rootdir0, list_0[id_0]) if os.path.isfile(path): print(path) train_data = np.load(path) train_data = add_noise(train_data) train_len = int((len(train_data) - 5120) / 5120 + 1) for sub_id in range(0, train_len): sub_train_data = train_data[sub_id * 5120:sub_id * 5120 + 5120] str_num_train = str(num_train) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/train_data/" + str_num_train + "_train.npy", sub_train_data) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/train_lab/" + str_num_train + "_lab.npy", lab0) num_train += 1 for id_0 in range(0, len(T_list_0)): path = os.path.join(T_rootdir0, T_list_0[id_0]) if os.path.isfile(path): print(path) test_data = np.load(path) train_data = add_noise(train_data) test_len = int((len(test_data) - 5120) / 5120 + 1) for sub_id in range(0, test_len): sub_test_data = test_data[sub_id * 5120:sub_id * 5120 + 5120] str_num_test = str(num_test) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/test_data/" + str_num_test + "_test.npy", sub_test_data) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/test_lab/" + str_num_test + "_lab.npy", lab0) str_detail_num = str(detail_num) np.save("../GB_data/" + Fault + "/noise_data/" + snr_str + "/test_detail/0/" + str_detail_num + "_test.npy", sub_test_data) np.save( "../GB_data/" + Fault + "/noise_data/" + snr_str + "/test_lab_detail/0/" + str_detail_num + "_lab.npy", lab0) detail_num += 1 num_test += 1
时间: 2024-04-04 18:35:54 浏览: 47
这是一段Python代码,它从一个文件夹中读取数据,对每个数据进行噪声添加,并将处理后的数据和标签保存到不同的文件夹中。其中,训练数据被保存到"../GB_data/Fault/noise_data/snr_str/train_data/"文件夹中,测试数据被保存到"../GB_data/Fault/noise_data/snr_str/test_data/"文件夹中,详细的测试数据被保存到"../GB_data/Fault/noise_data/snr_str/test_detail/0/"文件夹中。这段代码还使用了numpy库来处理数据。
阅读全文