How to use within_range method in Sure

Best Python code snippet using sure_python

augment.py

Source:augment.py Github

copy

Full Screen

1#!/usr/bin/env python2# coding: utf-834# # Data distribution check56# In[14]:789import numpy as np10import os11import pandas as pd12import matplotlib.pyplot as plt13#import umap as umap1415"""16# In[24]:171819# Read the old and new data 20old = pd.read_csv('data_x_old.csv', header=None,sep=' ',dtype='float')21old.info()22old = old.values23new = pd.read_csv('data_x.csv', header=None,sep=' ',dtype='float')24new.info()25new = new.values262728# ## Histogram2930# In[29]:313233# Plot the histogram of data34def histogram_plot(data, dim):35 f = plt.figure()36 # Determine if this is a new data37 if np.shape(data)[0] == 17500:38 new_flag = True39 name = 'new'40 else:41 new_flag = False42 name = 'old'43 # Plot the histogram44 plt.hist(data[:, dim],bins=100)45 plt.title('histogram of axim {} of {} data '.format(dim, name))46 plt.ylabel('cnt')47 plt.xlabel('axis {}'.format(dim))48 plt.savefig('histogram of axim {} of {} data.png'.format(dim, name))495051# In[30]:525354for i in range(8):55 histogram_plot(new, i)56 histogram_plot(old, i)575859# ## Clustering6061# In[31]:626364data_all = np.concatenate([old, new])65reducer = umap.UMAP()66embedding = reducer.fit_transform(data_all)67embedding.shape686970# In[37]:717273# Plot the umap graph74lo = len(old)75ln = len(new)76label_all = np.zeros([lo + ln, ])77label_all[lo:] = 178f = plt.figure()79plt.scatter(embedding[:lo, 0], embedding[:lo, 1], label='old',s=1)80plt.legend()81plt.xlabel('u1')82plt.ylabel('u2')83plt.title('umap plot for old data')84plt.savefig('umap plot for old data.png')85f = plt.figure()86plt.scatter(embedding[lo:, 0], embedding[lo:, 1], label='new',s=1)87plt.legend()88plt.xlabel('u1')89plt.ylabel('u2')90plt.title('umap plot for new data')91plt.savefig('umap plot for new data.png')92f = plt.figure()93plt.scatter(embedding[:lo, 0], embedding[:lo, 1], label='old',s=1)94plt.scatter(embedding[lo:, 0], embedding[lo:, 1], label='new',s=1)95plt.legend()96plt.xlabel('u1')97plt.ylabel('u2')98plt.title('umap plot for old data and new data')99plt.savefig('umap plot for old data and new data.png')100101102# ## Visualization103# 104105# In[12]:106107108def plot_scatter(old, new, dim1, dim2):109 f = plt.figure()110 plt.scatter(old[:, dim1], old[:, dim2], label='old',marker='x')#,s=10)111 plt.scatter(new[:, dim1], new[:, dim2], label='new',marker='.')#,s=5)112 plt.legend()113 plt.xlabel('dim {}'.format(dim1))114 plt.ylabel('dim {}'.format(dim2))115 plt.title('scatter plot of dim{},{} of old and new data'.format(dim1, dim2))116 plt.savefig('scatter plot of dim{},{} of old and new data.png'.format(dim1, dim2))117118119# In[15]:120121122for i in range(8):123 for j in range(8):124 if i == j:125 continue126 plot_scatter(old, new, i, j)127 plt.close('all')128129130# ## Pair-wise scatter plot131132# In[19]:133134135df_old = pd.DataFrame(old)136df_new = pd.DataFrame(new)137psm = pd.plotting.scatter_matrix(df_old, figsize=(15, 15), s=10)138139140# ## Find the same and plot spectra141142# In[38]:143144145i = 0146for i in range(len(old)):147 #print(old[i,:])148 new_minus = np.sum(np.square(new - old[i,:]),axis=1)149 #print(np.shape(new_minus))150 match = np.where(new_minus==0)151 #print(match)152 if np.shape(match)[1] != 0: #There is a match153 print('we found a match! new index {} and old index {} match'.format(match, i))154155156# In[39]:157158159print('old index ', old[11819,:])160print('new index ', new[5444,:])161162163# In[35]:164165166np.shape(match)167168169# ### Plot the matched spectra170171# In[6]:172173174y_old = pd.read_csv('data_y_old.csv',header=None,sep=' ')175176177# In[42]:178179180y_new = pd.read_csv('data_y_new.csv',header=None,sep=' ')181182183# In[7]:184185186y_old = y_old.values187y_new = y_new.values188189190# In[45]:191192193# plot the spectra194old_index = 11819195new_index = 5444196f = plt.figure()197plt.plot(y_old[old_index,:],label='old geometry {}'.format(old[old_index, :]))198plt.plot(y_new[new_index,:],label='new geometry {}'.format(new[new_index, :]))199plt.legend()200plt.ylabel('transmission')201plt.xlabel('THz')202plt.savefig('Spectra plot for identicle point')203204205# # Conclusion, this simulation is not the same as before ...206207# ### See what percentage are still within range208209# In[36]:210211212#print(old)213#print(new)214hmax = np.max(old[:,0])215hmin = np.min(old[:,1])216rmax = np.max(old[:,4])217rmin = np.min(old[:,4])218219print(hmax, hmin, rmax, rmin)220221#hmax = np.max(new[:,0])222#hmin = np.min(new[:,1])223#rmax = np.max(new[:,4])224#rmin = np.min(new[:,4])225226#print(hmax, hmin, rmax, rmin)227228within_range = np.ones([len(new)])229230new_minus = np.copy(new)231new_minus[:,:4] -= hmin232new_minus[:,4:] -= rmin233234new_plus = np.copy(new)235new_plus[:, :4] -= hmax236new_plus[:, 4:] -= rmax237238small_flag = np.min(new_minus, axis=1) < 0239big_flag = np.max(new_plus, axis=1) > 0240241within_range[small_flag] = 0242within_range[big_flag] = 0243244print(np.sum(within_range) / len(within_range))245print(type(within_range))246print(np.shape(within_range))247print(within_range)248print(new[np.arange(len(within_range))[within_range.astype('bool')],:])249print(np.sum(within_range))250251252# # Data augmentation253# ## Since the geometry is symmetric, we can augment the data with permutations254255# In[13]:256257258# Check the assumption that the permutation does indeed give you the same spectra259# Check if there is same spectra260i = 0261for i in range(len(y_old)):262 #print(old[i,:])263 new_minus = np.sum(np.square(y_old - y_old[i,:]),axis=1)264 #print(np.shape(new_minus))265 match = np.where(new_minus==0)266 #print(match)267 #print(np.shape(match))268 #print(len(match))269 #if match[0]270 if len(match) != 1:#np.shape(match)[1] != 0: #There is a match271 print('we found a match! new index {} and old index {} match'.format(match, i))272273274# ### Due to physical periodic boundary condition, we can augment the data by doing permutations275276# In[39]:277"""278279def permutate_periodicity(geometry_in, spectra_in):280 """281 :param: geometry_in: numpy array of geometry [n x 8] dim282 :param: spectra_in: spectra of the geometry_in [n x k] dim283 :return: output of the augmented geometry, spectra [4n x 8], [4n x k]284 """285 # Get the dimension parameters286 (n, k) = np.shape(spectra_in)287 # Initialize the output288 spectra_out = np.zeros([4*n, k])289 geometry_out = np.zeros([4*n, 8])290 291 #################################################292 # start permutation of geometry (case: 1 - 0123)#293 #################################################294 # case:2 -- 1032 295 geometry_c2 = geometry_in[:, [1,0,3,2,5,4,7,6]]296 # case:3 -- 2301297 geometry_c3 = geometry_in[:, [2,3,0,1,6,7,4,5]]298 # case:4 -- 3210299 geometry_c4 = geometry_in[:, [3,2,1,0,7,6,5,4]]300 301 geometry_out[0*n:1*n, :] = geometry_in302 geometry_out[1*n:2*n, :] = geometry_c2303 geometry_out[2*n:3*n, :] = geometry_c3304 geometry_out[3*n:4*n, :] = geometry_c4305 306 for i in range(4):307 spectra_out[i*n:(i+1)*n,:] = spectra_in308 return geometry_out, spectra_out309310311# In[40]:312data_folder = '/work/sr365/Christian_data/dataIn'313data_out_folder = '/work/sr365/Christian_data_augmented'314for file in os.listdir(data_folder):315 data = pd.read_csv(os.path.join(data_folder, file),header=None,sep=',').values316 (l, w) = np.shape(data)317 g = data[:,2:10]318 s = data[:,10:]319 g_aug, s_aug = permutate_periodicity(g, s)320 output = np.zeros([l*4, w])321 output[:, 2:10] = g_aug322 output[:, 10:] = s_aug323 np.savetxt(os.path.join(data_out_folder, file+'_augmented.csv'),output,delimiter=',')324325# In[41]:326327328#print(np.shape(g))329330331# In[ ]:332333334 ...

Full Screen

Full Screen

unicornosaurus.py

Source:unicornosaurus.py Github

copy

Full Screen

1import numpy as np2import itertools3n_sections_broken, n_possible_fixes, IDK = list(map(int, input().split(' ')))4sections_broken = []5possible_fixes = []6power_construction = []7for _ in range(n_sections_broken):8 sections_broken.append(tuple(map(int, input().split(' '))))9for _ in range(n_possible_fixes):10 possible_fixes.append((list(map(int, input().split(' ')))))11within_range = []12for possible_fix in possible_fixes:13 for section in sections_broken:14 if possible_fix[0] <= section[0] or possible_fix[1] >= section[1]:15 within_range.append(possible_fix)16within_range = sorted(within_range)17for i in range(len(within_range)):18 for y in range(i, len(within_range)):19 try:20 if within_range[i][0] < within_range[y][0] and within_range[i][1] > within_range[y][1]:21 within_range.remove(within_range[y])22 except IndexError:23 continue24within_range = list(itertools.product(within_range, within_range))25within_range = list(dict.fromkeys(map(str, within_range)))26within_range = list(map(eval, within_range))27for i in range(len(within_range)):28 if within_range[i][0] == within_range[i][1]:29 within_range[i] = tuple(within_range[i][0])30 else:31 within_range[i] = min(within_range[i][0][0] , within_range[i][1][0]), max(within_range[i][0][1], within_range[i][1][1]), \32 (within_range[i][0][2] + within_range[i][1][2])33within_range = sorted(within_range)34# print(within_range)35power_need = []36found_start = False37section_x = min(sections_broken)[0]38section_y = max(sections_broken)[1]39# print(section_x, section_y)40completed = False41for i in range(len(within_range)):42 if within_range[i][0] <= section_x and within_range[i][1] >= section_y:43 if found_start:44 power_need.pop()45 power_need.append(within_range[i][2])46 completed = True47 found_start = False48 break49 elif not found_start and within_range[i][0] <= section_x:50 power_need.append(within_range[i][2])51 found_start = True52 elif found_start and within_range[i][1] >= section_y:53 found_start = False54 completed = True55 break56if not completed:57 print(-1)58else:59 print(-1)60"""611 3 15625 10633 7 2646 12 5652 11 6662 4 15673 7689 10692 6 10703 9 15715 12 13728 10 30...

Full Screen

Full Screen

01-Milestone1.py

Source:01-Milestone1.py Github

copy

Full Screen

1import os2os.system('cls')3def user_choice():4 #VARIABLES5 6 #Initial7 choice = 'Wrong'8 acceptable_values = range(0,10)9 within_range = False10 #TWO CONDITIONS TO CHECK11 # DIGIT OR WITHIN RANGE == FALSE12 while choice.isdigit() == False or within_range == False:13 choice = input("Please enter a number (0-10): ")14 #DIGIT CHECK15 if choice.isdigit() == False:16 print("Sorry, wrong value")17 #RANGE CHECK18 if choice.isdigit() == True:19 if int(choice) in acceptable_values:20 within_range = True21 else:22 print('Out of acceptable range (0-10)')23 within_range = False24 return int(choice)25def display(row1,row2,row3):26 print(row1)27 print(row2)28 print(row3)29row1 = [' ',' ',' ']30row2 = [' ',' ',' ']31row3 = [' ',' ',' ']32display(row1,row2,row3)33position_index = user_choice()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Sure automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful