def build_template(tab_filter, preference): # If tab_filter is not a string, make it an empty string if not isinstance(tab_filter, str): tab_filter = '' template = TABS_TEMPLATE.replace('%FILTER%', tab_filter) if isinstance(preference, str) and preference != '': return template.replace('%PREFERENCE%', 'data-tab-preference="{}"'.format(preference)) return template.replace('%PREFERENCE%', '')
def buildTemplate(tabFilter, preference): # If tabFilter is not a string, make it an empty string if type(tabFilter) != str: tabFilter = "" template = TABS_TEMPLATE.replace("%FILTER%", tabFilter) if type(preference) == str and preference != "": template = template.replace("%PREFERENCE%", "data-tab-preference=\"" + preference + "\"") else: template = template.replace("%PREFERENCE%", "") return template
p_i = p_list[i] n_i = n_list[i] distance_a_p = np.linalg.norm(a_i - p_i)**2 distance_a_n = np.linalg.norm(a_i - n_i)**2 result['distance_{}_a_p'.format(i)] = distance_a_p result['distance_{}_a_n'.format(i)] = distance_a_n for j in range(num_samples): a_j = a_list[j] p_j = p_list[j] n_j = n_list[j] distance_i_j_a = np.linalg.norm(a_i - a_j)**2 distance_i_j_p = np.linalg.norm(p_i - p_j)**2 distance_i_j_n = np.linalg.norm(n_i - n_j)**2 result['distance_{}_{}_a'.format(i, j)] = distance_i_j_a result['distance_{}_{}_p'.format(i, j)] = distance_i_j_p result['distance_{}_{}_n'.format(i, j)] = distance_i_j_n with open('result.json', 'w') as file: json.dump(result, file, indent=4) from template import replace replace() K.clear_session()