import os, sys import numpy as np from pprint import pprint np_raw_results_csv = np.genfromtxt( "np_raw_results.csv", delimiter=",", dtype=[ ("img_test_path", "U50"), ("diff_gray", "f8"), ("diff_rgb", "f8"), ("sift_match", "f8"), ("diff_contour", "f8"), ("d_cld_full", "f8"), ("d_cld_up", "f8"), ("d_cld_down", "f8"), ("d_cld_left", "f8"), ("d_cld_right", "f8"), ], ) np_raw_results = np.array([list(row) for row in np_raw_results_csv]) pprint(np_raw_results) weight_diff_gray = 0.5 weight_diff_rgb = 0.5 weight_diff_sift = 0 weight_diff_contour = 0 weight_diff_cld = 0 weight_diff_u = 0 weight_diff_d = 0 weight_diff_l = 0 weight_diff_r = 0 min_values = np.min(np_raw_results[:, 1:].astype(np.float64), axis=0) max_values = np.max(np_raw_results[:, 1:].astype(np.float64), axis=0) normalized_array = (np_raw_results[:, 1:].astype(np.float64) - min_values) / (max_values - min_values) np_raw_results = np.concatenate((np_raw_results, normalized_array), axis=1) start_col = 9 np_raw_results[:, start_col + 1] = np_raw_results[:, start_col + 1].astype(np.float64) * weight_diff_gray np_raw_results[:, start_col + 2] = np_raw_results[:, start_col + 2].astype(np.float64) * weight_diff_rgb np_raw_results[:, start_col + 3] = (1 - np_raw_results[:, start_col + 3].astype(np.float64)) * weight_diff_sift np_raw_results[:, start_col + 4] = np_raw_results[:, start_col + 4].astype(np.float64) * weight_diff_contour # np_raw_results[:, start_col + 5] = np_raw_results[:, start_col + 5].astype(np.float64) * weight_diff_cld np_raw_results[:, start_col + 6] = np_raw_results[:, start_col + 6].astype(np.float64) * weight_diff_u np_raw_results[:, start_col + 7] = np_raw_results[:, start_col + 7].astype(np.float64) * weight_diff_d np_raw_results[:, start_col + 8] = np_raw_results[:, start_col + 8].astype(np.float64) * weight_diff_l np_raw_results[:, start_col + 9] = np_raw_results[:, start_col + 9].astype(np.float64) * weight_diff_r diff_sums = np.sum(np_raw_results[:, 10:-1].astype(np.float64), axis=1) np_raw_results = np.concatenate((np_raw_results, diff_sums[:, np.newaxis]), axis=1) np_raw_results = np.concatenate( (np_raw_results, np.array([row[0].replace("image.orig/", "")[0] for row in np_raw_results])[:, np.newaxis]), axis=1 ) np_raw_results = np.concatenate((np_raw_results, np_raw_results[:, 0][:, np.newaxis]), axis=1) np_raw_results_sorted = np_raw_results[np.argsort(np_raw_results[:, -3].astype(np.float64))] raw_results = np_raw_results_sorted.tolist() column_names = [ "img_test_path", "diff_gray", "diff_rgb", "sift_match", "diff_contour", "d_cld_full", "d_cld_up", "d_cld_down", "d_cld_left", "d_cld_right", # "w_gray", "w_rgb", "w_sift_match", "w_contour", "w_cld_full", "w_cld_up", "w_cld_down", "w_cld_left", "w_cld_right", "w_sum", "category", "image", ] np.savetxt( "np_raw_results_sorted.csv", np_raw_results_sorted, delimiter=",", fmt="%s", header=",".join(column_names), comments="", ) # np.savetxt("np_raw_results_sorted.csv", np_raw_results_sorted, delimiter=",", fmt="%f") print(np_raw_results)