How to use ls method in fMBT

Best Python code snippet using fMBT_python

non_greedy_mv.py

Source:non_greedy_mv.py Github

copy

Full Screen

...11from matplotlib.collections import LineCollection12from matplotlib import colors as mcolors13import numpy as np14import math15def draw_mv_ls(axis, mv_ls, mode=0):16 colors = np.array([(1., 0., 0., 1.)])17 segs = np.array([18 np.array([[ptr[0], ptr[1]], [ptr[0] + ptr[2], ptr[1] + ptr[3]]])19 for ptr in mv_ls20 ])21 line_segments = LineCollection(22 segs, linewidths=(1.,), colors=colors, linestyle='solid')23 axis.add_collection(line_segments)24 if mode == 0:25 axis.scatter(mv_ls[:, 0], mv_ls[:, 1], s=2, c='b')26 else:27 axis.scatter(28 mv_ls[:, 0] + mv_ls[:, 2], mv_ls[:, 1] + mv_ls[:, 3], s=2, c='b')29def draw_pred_block_ls(axis, mv_ls, bs, mode=0):30 colors = np.array([(0., 0., 0., 1.)])31 segs = []32 for ptr in mv_ls:33 if mode == 0:34 x = ptr[0]35 y = ptr[1]36 else:37 x = ptr[0] + ptr[2]38 y = ptr[1] + ptr[3]39 x_ls = [x, x + bs, x + bs, x, x]40 y_ls = [y, y, y + bs, y + bs, y]41 segs.append(np.column_stack([x_ls, y_ls]))42 line_segments = LineCollection(43 segs, linewidths=(.5,), colors=colors, linestyle='solid')44 axis.add_collection(line_segments)45def read_frame(fp, no_swap=0):46 plane = [None, None, None]47 for i in range(3):48 line = fp.readline()49 word_ls = line.split()50 word_ls = [int(item) for item in word_ls]51 rows = word_ls[0]52 cols = word_ls[1]53 line = fp.readline()54 word_ls = line.split()55 word_ls = [int(item) for item in word_ls]56 plane[i] = np.array(word_ls).reshape(rows, cols)57 if i > 0:58 plane[i] = plane[i].repeat(2, axis=0).repeat(2, axis=1)59 plane = np.array(plane)60 if no_swap == 0:61 plane = np.swapaxes(np.swapaxes(plane, 0, 1), 1, 2)62 return plane63def yuv_to_rgb(yuv):64 #mat = np.array([65 # [1.164, 0 , 1.596 ],66 # [1.164, -0.391, -0.813],67 # [1.164, 2.018 , 0 ] ]68 # )69 #c = np.array([[ -16 , -16 , -16 ],70 # [ 0 , -128, -128 ],71 # [ -128, -128, 0 ]])72 mat = np.array([[1, 0, 1.4075], [1, -0.3445, -0.7169], [1, 1.7790, 0]])73 c = np.array([[0, 0, 0], [0, -128, -128], [-128, -128, 0]])74 mat_c = np.dot(mat, c)75 v = np.array([mat_c[0, 0], mat_c[1, 1], mat_c[2, 2]])76 mat = mat.transpose()77 rgb = np.dot(yuv, mat) + v78 rgb = rgb.astype(int)79 rgb = rgb.clip(0, 255)80 return rgb / 255.81def read_feature_score(fp, mv_rows, mv_cols):82 line = fp.readline()83 word_ls = line.split()84 feature_score = np.array([math.log(float(v) + 1, 2) for v in word_ls])85 feature_score = feature_score.reshape(mv_rows, mv_cols)86 return feature_score87def read_mv_mode_arr(fp, mv_rows, mv_cols):88 line = fp.readline()89 word_ls = line.split()90 mv_mode_arr = np.array([int(v) for v in word_ls])91 mv_mode_arr = mv_mode_arr.reshape(mv_rows, mv_cols)92 return mv_mode_arr93def read_frame_dpl_stats(fp):94 line = fp.readline()95 word_ls = line.split()96 frame_idx = int(word_ls[1])97 mi_rows = int(word_ls[3])98 mi_cols = int(word_ls[5])99 bs = int(word_ls[7])100 ref_frame_idx = int(word_ls[9])101 rf_idx = int(word_ls[11])102 gf_frame_offset = int(word_ls[13])103 ref_gf_frame_offset = int(word_ls[15])104 mi_size = bs / 8105 mv_ls = []106 mv_rows = int((math.ceil(mi_rows * 1. / mi_size)))107 mv_cols = int((math.ceil(mi_cols * 1. / mi_size)))108 for i in range(mv_rows * mv_cols):109 line = fp.readline()110 word_ls = line.split()111 row = int(word_ls[0]) * 8.112 col = int(word_ls[1]) * 8.113 mv_row = int(word_ls[2]) / 8.114 mv_col = int(word_ls[3]) / 8.115 mv_ls.append([col, row, mv_col, mv_row])116 mv_ls = np.array(mv_ls)117 feature_score = read_feature_score(fp, mv_rows, mv_cols)118 mv_mode_arr = read_mv_mode_arr(fp, mv_rows, mv_cols)119 img = yuv_to_rgb(read_frame(fp))120 ref = yuv_to_rgb(read_frame(fp))121 return rf_idx, frame_idx, ref_frame_idx, gf_frame_offset, ref_gf_frame_offset, mv_ls, img, ref, bs, feature_score, mv_mode_arr122def read_dpl_stats_file(filename, frame_num=0):123 fp = open(filename)124 line = fp.readline()125 width = 0126 height = 0127 data_ls = []128 while (line):129 if line[0] == '=':130 data_ls.append(read_frame_dpl_stats(fp))131 line = fp.readline()132 if frame_num > 0 and len(data_ls) == frame_num:133 break134 return data_ls135if __name__ == '__main__':136 filename = sys.argv[1]137 data_ls = read_dpl_stats_file(filename, frame_num=5)138 for rf_idx, frame_idx, ref_frame_idx, gf_frame_offset, ref_gf_frame_offset, mv_ls, img, ref, bs, feature_score, mv_mode_arr in data_ls:139 fig, axes = plt.subplots(2, 2)140 axes[0][0].imshow(img)141 draw_mv_ls(axes[0][0], mv_ls)142 draw_pred_block_ls(axes[0][0], mv_ls, bs, mode=0)143 #axes[0].grid(color='k', linestyle='-')144 axes[0][0].set_ylim(img.shape[0], 0)145 axes[0][0].set_xlim(0, img.shape[1])146 if ref is not None:147 axes[0][1].imshow(ref)148 draw_mv_ls(axes[0][1], mv_ls, mode=1)149 draw_pred_block_ls(axes[0][1], mv_ls, bs, mode=1)150 #axes[1].grid(color='k', linestyle='-')151 axes[0][1].set_ylim(ref.shape[0], 0)152 axes[0][1].set_xlim(0, ref.shape[1])153 axes[1][0].imshow(feature_score)154 #feature_score_arr = feature_score.flatten()155 #feature_score_max = feature_score_arr.max()156 #feature_score_min = feature_score_arr.min()157 #step = (feature_score_max - feature_score_min) / 20.158 #feature_score_bins = np.arange(feature_score_min, feature_score_max, step)159 #axes[1][1].hist(feature_score_arr, bins=feature_score_bins)160 im = axes[1][1].imshow(mv_mode_arr)161 #axes[1][1].figure.colorbar(im, ax=axes[1][1])162 print rf_idx, frame_idx, ref_frame_idx, gf_frame_offset, ref_gf_frame_offset, len(mv_ls)163 flatten_mv_mode = mv_mode_arr.flatten()...

Full Screen

Full Screen

test_transforms.py

Source:test_transforms.py Github

copy

Full Screen

...54 ifls = [S(533)/672 + 3*I/2, S(23)/224 + I/2, S(1)/672, S(107)/224 - I,55 S(155)/672 + 3*I/2, -S(103)/224 + I/2, -S(377)/672, -S(19)/224 - I]56 assert ifwht(ls) == ifls57 assert fwht(ifls) == ls + [S.Zero]*358 x, y = symbols('x y')59 raises(TypeError, lambda: fwht(x))60 ls = [x, 2*x, 3*x**2, 4*x**3]61 ifls = [x**3 + 3*x**2/4 + 3*x/4,62 -x**3 + 3*x**2/4 - x/4,63 -x**3 - 3*x**2/4 + 3*x/4,64 x**3 - 3*x**2/4 - x/4]65 assert ifwht(ls) == ifls66 assert fwht(ifls) == ls67 ls = [x, y, x**2, y**2, x*y]68 fls = [x**2 + x*y + x + y**2 + y,69 x**2 + x*y + x - y**2 - y,70 -x**2 + x*y + x - y**2 + y,71 -x**2 + x*y + x + y**2 - y,72 x**2 - x*y + x + y**2 + y,73 x**2 - x*y + x - y**2 - y,74 -x**2 - x*y + x - y**2 + y,75 -x**2 - x*y + x + y**2 - y]76 assert fwht(ls) == fls77 assert ifwht(fls) == ls + [S.Zero]*378 ls = list(range(6))79 assert fwht(ls) == [x*8 for x in ifwht(ls)]80def test_mobius_transform():81 assert all(tf(ls, subset=subset) == ls82 for ls in ([], [S(7)/4]) for subset in (True, False)83 for tf in (mobius_transform, inverse_mobius_transform))84 w, x, y, z = symbols('w x y z')85 assert mobius_transform([x, y]) == [x, x + y]86 assert inverse_mobius_transform([x, x + y]) == [x, y]87 assert mobius_transform([x, y], subset=False) == [x + y, y]88 assert inverse_mobius_transform([x + y, y], subset=False) == [x, y]89 assert mobius_transform([w, x, y, z]) == [w, w + x, w + y, w + x + y + z]90 assert inverse_mobius_transform([w, w + x, w + y, w + x + y + z]) == \91 [w, x, y, z]92 assert mobius_transform([w, x, y, z], subset=False) == \93 [w + x + y + z, x + z, y + z, z]94 assert inverse_mobius_transform([w + x + y + z, x + z, y + z, z], subset=False) == \95 [w, x, y, z]96 ls = [S(2)/3, S(6)/7, S(5)/8, 9, S(5)/3 + 7*I]97 mls = [S(2)/3, S(32)/21, S(31)/24, S(1873)/168,98 S(7)/3 + 7*I, S(67)/21 + 7*I, S(71)/24 + 7*I,...

Full Screen

Full Screen

63010841_Lab9_03.py

Source:63010841_Lab9_03.py Github

copy

Full Screen

1# รับจำนวนเต็มมา 1 จำนวนแล้วให้แสดงผลดังนี้2# - หาก input ที่รับมานั้นมีการเรียงลำดับจากน้อยไปมาก และไม่มีตัวซ้ำเลยให้แสดงผลว่า "Metadrome"3# - หาก input ที่รับมานั้นมีการเรียงลำดับจากน้อยไปมาก และมีตัวซ้ำให้แสดงผลว่า "Plaindrome"4# - หาก input ที่รับมานั้นมีการเรียงลำดับจากมากไปน้อย และไม่มีตัวซ้ำเลยให้แสดงผลว่า "Katadrome"5# - หาก input ที่รับมานั้นมีการเรียงลำดับจากมากไปน้อย และมีตัวซ้ำให้แสดงผลว่า "Nialpdrome"6# - หาก input ที่รับมานั้นทุกหลักเป็นเลขเดียวกันหมด ให้แสดงผลว่า "Repdrome"7# - หากไม่อยู่ในเงื่อนไขด้านบนเลย ให้แสดงผลว่า "Nondrome"8# ****** ห้ามใช้ Built-in Function ที่เกี่ยวกับ Sort ให้น้องเขียนฟังก์ชัน Sort เอง9def bubble_sort_acend(ls):10 for i in range(len(ls)):11 for j in range(len(ls) - 1):12 if ls[j] > ls[j+1]:13 # Swap14 ls[j], ls[j+1] = ls[j+1], ls[j]15 return ls16def bubble_sort_decend(ls):17 for i in range(len(ls)):18 for j in range(len(ls) - 1):19 if ls[j] < ls[j+1]:20 # Swap21 ls[j], ls[j+1] = ls[j+1], ls[j]22 return ls23 24def ascending_order(ls):25 copy = ls[::]26 copy = bubble_sort_acend(copy)27 return ls == copy28def decending_order(ls):29 copy = ls[::]30 copy = bubble_sort_decend(copy)31 return ls == copy32def doub_check(ls):33 for i in range(len(ls)):34 for j in range(i+1,len(ls)):35 if ls[i] == ls[j]:36 return True37 return False38def same_check(ls):39 for i in range(len(ls)):40 if ls[0] != ls[i]:41 return False42 return True43inp = [int(x) for x in input('Enter Input : ')]44decending_order(inp)45# Metadrome46if ascending_order(inp) and not doub_check(inp) and not same_check(inp):47 print('Metadrome')48# Plaindrome49elif ascending_order(inp) and doub_check(inp) and not same_check(inp):50 print('Plaindrome')51# Katadrome52elif decending_order(inp) and not doub_check(inp) and not same_check(inp):53 print('Katadrome')54# Nialpdrome55elif decending_order(inp) and doub_check(inp) and not same_check(inp):56 print('Nialpdrome')57# Repdrome58elif same_check(inp):59 print('Repdrome')60# Nondrome61else:...

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 fMBT 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