Coding the matrix: Linear Algebra
Through Computer Science Applications
This is a course for implementing matrix operations using python. For the first assignment, I felt that python was greatly improved and various data types were used.
The Code is as follows:
## Task 1minutes_in_week = 60*24*7## Task 2remainder_without_mod = 2304811-2304811//47*47## Task 3divisible_by_3 = (673+909)/3==0## Task 4x = -9y = 1/2statement_val = 2**(y+1/2) if x+10<0 else 2**(y-1/2)## Task 5first_five_squares = { x*x for x in {1,2,3,4,5} }## Task 6first_five_pows_two = { 2**x for x in {0,1,2,3,4} }## Task 7: enter in the two new setsX1 = { 1, 2, 3 }Y1 = { 4, 11, 17 }## Task 8: enter in the two new setsX2 = { 1, 2, 0 }Y2 = { 4, 8, 16 }## Task 9base = 10digits = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}three_digits_set = { base**2*x+base*y+z for x in digits for y in digits for z in digits }## Task 10S = {1, 2, 3, 4}T = {3, 4, 5, 6}S_intersect_T = { x for x in S if x in T }## Task 11L_average = sum([20, 10, 15, 75])/len([20, 10, 15, 75]) # average of: [20, 10, 15, 75]## Task 12LofL = [[.25, .75, .1], [-1, 0], [4, 4, 4, 4]]LofL_sum = sum({sum(LofL[x]) for x in range(0,len(LofL))}) # use form: sum([sum(...) ... ])## Task 13cartesian_product = [[x,y] for x in {'A','B','C'} for y in {1,2,3} ] # use form: [ ... {'A','B','C'} ... {1,2,3} ... ]## Task 14S = {-4, -2, 1, 2, 5, 0}zero_sum_list = [ (x,y,z) for x in S for y in S for z in S if x+y+z==0 ] ## Task 15exclude_zero_list = [ (x,y,z) for x in S for y in S for z in S if (x+y+z==0) and (x or y or z) ]## Task 16first_of_tuples_list = [ (x,y,z) for x in S for y in S for z in S if (x+y+z==0) and (x or y or z) ][0]## Task 17L1 = [1,1,2] # <-- want len(L1) != len(list(set(L1)))L2 = [2,1,3] # <-- same len(L2) == len(list(set(L2))) but L2 != list(set(L2))## Task 18odd_num_list_range = { x for x in range(1,100,2)}## Task 19L = ['A','B','C','D','E']range_and_zip = list(zip(list(range(5)),L))## Task 20list_sum_zip = [x+y for (x,y) in zip([10,25,40],[1,15,20])]## Task 21dlist = [{'James':'Sean', 'director':'Terence'}, {'James':'Roger', 'director':'Lewis'}, {'James':'Pierce', 'director':'Roger'}]k = 'James'value_list = [d[k] for d in dlist]## Task 22dlist = [{'Bilbo':'Ian','Frodo':'Elijah'},{'Bilbo':'Martin','Thorin':'Richard'}]k = 'Bilbo'value_list_modified_1 = [d[k] if k in d else 'NOT PRESENT' for d in dlist] # <-- Use the same expression herek = 'Frodo'value_list_modified_2 = [d[k] if k in d else 'NOT PRESENT' for d in dlist] # <-- as you do here## Task 23square_dict = {x:x**2 for x in range(100)}## Task 24D = {'red','white','blue'}identity_dict = {x:x for x in D}## Task 25base = 10digits = set(range(10))representation_dict = { base**2*x+base*y+z:[x,y,z] for x in digits for y in digits for z in digits}## Task 26d = {0:1000.0, 1:1200.50, 2:990}names = ['Larry', 'Curly', 'Moe']listdict2dict = { names[x]:y for (x,y) in d.items() }## Task 27def nextInts(L): return [ x+1 for x in L ]## Task 28def cubes(L): return [ x**3 for x in L ] ## Task 29def dict2list(dct, keylist): return [ dct[x] for x in keylist ]## Task 30 def list2dict(L, keylist): return { x:y for (x,y) in zip(keylist,L) }
The scoring system has some bugs, such as task2 which cannot be enclosed by brackets. If an error occurs, compare the errors.
Submission method:
Submit in Linux according to the instructions, but in Windows, it takes a lot of effort.
Because the default py file to be submitted in submit_python_lab.py is in the current directory, you must copy the py file and submit_python_lab.py file to the installation folder of python3. I use python3.3, so the directory to be copied is c: \ python33. Double-click submit_python_lab.py in the Forum and enter the account and password. To facilitate the running of the bat script file:
C:\Python33\python C:\Python33\submit_python_lab.py