Best Python code snippet using assertpy_python
infer_2D.py
Source:infer_2D.py
1import Bayesian_Hilbert_Maps.BHM.original.sbhm as sbhm2from aux_funcs import *3import agent2D 4import rrt_BHM 5import matplotlib.pyplot as plt6valid_starting_points1 = [(56, 56), (112, 56), (168, 56), (168, 112), (112, 112)] # X, Y for Drone 17valid_starting_points2 = [(168, 168), (112, 168), (56, 168), (56, 112), (112, 112)] # X, Y for Drone 28# Training map9gt = get_ground_truth_array(r'/Users/axtonlim/Desktop/PEDRA_2D/map_2D/environments/filled_simple_floorplan_v2.png')10plt.imshow(gt, 'Greys_r')11plt.show()12# Paths13custom_load_dir1 = '/Users/axtonlim/Desktop/PEDRA_2D/map_2D/results/weights1/drone_2D_6000'14custom_load_dir2 = '/Users/axtonlim/Desktop/PEDRA_2D/map_2D/results/weights2/drone_2D_6000'15log_dir1 = '/Users/axtonlim/Desktop/PEDRA_2D/map_2D/results/inference1/infer_log.txt'16log_dir2 = '/Users/axtonlim/Desktop/PEDRA_2D/map_2D/results/inference2/infer_log.txt'17# RRT variables18danger_radius = 419occ_threshold = 0.720# SBHM variables21gamma = 0.0222cell_res = (12, 12)23min_max = (0, 223, 0, 223)24LIDAR_max_range = 7625BHM = sbhm.SBHM(gamma=gamma, cell_resolution=cell_res, cell_max_min=min_max)26# agent27drone1 = agent2D.agent_2D(BHM=BHM, min_max=min_max, LIDAR_pixel_range=LIDAR_max_range, ground_truth_map=gt, starting_pos=valid_starting_points1[0],28 plot_dir='', weights_dir='', custom_load=custom_load_dir1)29drone2 = agent2D.agent_2D(BHM=BHM, min_max=min_max, LIDAR_pixel_range=LIDAR_max_range, ground_truth_map=gt, starting_pos=valid_starting_points2[0],30 plot_dir='', weights_dir='', custom_load=custom_load_dir2)31drone1.collect_data() # need to do 1 fitting of BHM first before can query32drone2.collect_data()33current_state1 = drone1.get_state()34current_state2 = drone2.get_state()35# Inference Variables36cum_path_length1 = 037cum_path_length2 = 038minimum_finished_ratio = 0.7839plt.ion()40plt.show()41plt.scatter(drone1.position[0], drone1.position[1], drone2.position[0], drone2.position[1], cmap='jet')42print("******** INFERENCE BEGINS *********")43while True:44 no_dupe1 = drone1.network_model.action_selection_non_repeat(current_state1, current_state2, drone1.previous_actions)45 print('no dupe action1', no_dupe1[0])46 no_dupe2 = drone2.network_model.action_selection_non_repeat(current_state2, current_state1, drone2.previous_actions)47 print('no dupe action2', no_dupe2[0])48 # RRT* Algo49 startpos1 = drone1.position50 goalpos1 = action_idx_to_coords(no_dupe1[0], min_max)51 startpos2 = drone2.position52 goalpos2 = action_idx_to_coords(no_dupe2[0], min_max)53 G1 = rrt_BHM.Graph(startpos1, goalpos1, min_max)54 G1 = rrt_BHM.RRT_n_star(G1, drone1.BHM, n_iter=450, radius=5, stepSize=14, crash_radius=5, n_retries_allowed=0)55 G2 = rrt_BHM.Graph(startpos2, goalpos2, min_max)56 G2 = rrt_BHM.RRT_n_star(G2, drone2.BHM, n_iter=450, radius=5, stepSize=14, crash_radius=5, n_retries_allowed=0)57 if G1.success:58 path1 = rrt_BHM.dijkstra(G1)59 path1 = [(int(elem[0]), int(elem[1])) for elem in path1]60 _1, path_length1 = drone1.move_by_sequence(path1[1:]) # exclude first point61 cum_path_length1 += path_length162 else:63 path_length1 = 064 if G2.success:65 path2 = rrt_BHM.dijkstra(G2)66 path2 = [(int(elem[0]), int(elem[1])) for elem in path2]67 _2, path_length2 = drone2.move_by_sequence(path2[1:]) # exclude first point68 cum_path_length2 += path_length269 else:70 path_length2 = 071 done = False72 if path_length1 or path_length2 != 0:73 free_mask1 = drone1.get_free_mask()74 correct1 = np.logical_and(gt, free_mask1)75 free_mask2 = drone2.get_free_mask()76 correct2 = np.logical_and(gt, free_mask2)77 correct = correct1 + correct278 #plt.imshow(correct, cmap='Greys_r')79 plt.scatter(drone1.position[0], drone1.position[1], drone2.position[0], drone2.position[1], cmap='jet')80 plt.draw()81 plt.pause(0.001)82 #drone1.show_model()83 #drone2.show_model()84 finished_ratio = np.sum(correct) / np.sum(gt)85 print("Finished ratio:", finished_ratio)86 if finished_ratio > minimum_finished_ratio:87 done = True88 new_state1 = drone1.get_state()89 new_state2 = drone2.get_state()90 else:91 new_state1 = current_state192 new_state2 = current_state293 if done:94 print("******** EXPLORATION DONE *********")95 cum_path_length = cum_path_length1 + cum_path_length296 print("Path Length:", cum_path_length)97 print("Finished ratio:", finished_ratio)98 break99 else:100 current_state1 = new_state1101 current_state2 = new_state2102 drone1.previous_actions.add(tuple(no_dupe1[0]))...
day 3 solution.py
Source:day 3 solution.py
1# -*- coding: utf-8 -*-2with open("input.txt", 'r') as f:3 nums = [line for line in f.readlines()]4nums = [i.strip('\n') for i in nums]5nums_dupe1 = nums6nums_dupe2 = nums7empty = []8for i in range(len(nums[0])):9 counter = 010 for j in range(len(nums)):11 if int(nums[j][i]) == 1:12 counter+=113 else:14 counter-= 115 16 if counter >0:17 empty.append(1)18 else:19 empty.append(0)20 21 22binary = ''.join([str(i) for i in empty])23binary2 = binary.replace("1", "2").replace("0", "1").replace("2", "0")24print(int(binary,2))25print(int(binary2,2))26print(int(binary,2) * int(binary2,2))27#part 228empty2 = []29for i in range(len(nums_dupe1[0])):30 counter = 031 for j in range(len(nums_dupe1)):32 if int(nums_dupe1[j][i]) == 1:33 counter+=134 else:35 counter-= 136 if len(nums_dupe1) == 1:37 break38 if counter >= 0:39 nums_dupe1 = [x for x in nums_dupe1 if x[i] == '1']40 if counter < 0:41 nums_dupe1 = [x for x in nums_dupe1 if x[i] == '0']42print(nums_dupe1)43 44for i in range(len(nums_dupe2[0])):45 counter = 046 for j in range(len(nums_dupe2)):47 if int(nums_dupe2[j][i]) == 1:48 counter+=149 else:50 counter-= 151 if len(nums_dupe2) == 1:52 break53 if counter >= 0:54 nums_dupe2 = [x for x in nums_dupe2 if x[i] == '0']55 if counter < 0:56 nums_dupe2 = [x for x in nums_dupe2 if x[i] == '1']57print(nums_dupe2)58x1 =(int(nums_dupe1[0],2))59x2 =(int(nums_dupe2[0],2))60print(x1*x2)61 ...
deDupes.py
Source:deDupes.py
1'''attempting to deduplicate two sets of microform records in order to update the difference'''2import csv, os3with open('dupe1.csv', 'r') as file1, open('dupe2.csv', 'r') as file2:4 dupe1_reader = file1.read().split('\n')5 dupe2_reader = file2.read().split('\n')6 s = set(dupe2_reader)7 deDupes = [line for line in dupe1_reader if line not in s]8 with open('deDupes.csv', 'w') as dedupout:9 ded_writer = csv.writer(dedupout)10 for line in deDupes:11 ded_writer.writerow(line)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!