Coding the Matrix Week 0 作业
2013-07-29 03:38
495 查看
Coding the Matrix: Linear Algebra through Computer Science Applications
本次作业分成三部分,第一部分点击打开链接 已经记录过,后两部分也早已完成,趁有时间记下来。hw0 比较简单,如果有问题在论坛都可以找到答案。不过要注意使用python3运行。不过没有想到python里面也支持j作为虚数单位。
# Please fill out this stencil and submit using the provided submission script. ## Problem 1 def myFilter(L, num): return [x for x in L if x%num] ## Problem 2 def myLists(L): return [list(range(1,x+1)) for x in L] ## Problem 3 def myFunctionComposition(f, g): return {x:g[f[x]] for x in f.keys()} ## Problem 4 # Please only enter your numerical solution. complex_addition_a = 5+3j complex_addition_b = 0+1j complex_addition_c = -1+.001j complex_addition_d = .001+9j ## Problem 5 GF2_sum_1 = 1 GF2_sum_2 = 0 GF2_sum_3 = 0 ## Problem 6 def mySum(L): sumL=0 for x in L: sumL+=x return sumL ## Problem 7 def myProduct(L): sumL=1 for x in L: sumL*=x return sumL ## Problem 8 def myMin(L): sumL=L[0] for x in L: if sumL>x: sumL=x return sumL ## Problem 9 def myConcat(L): output='' for x in L: output+=x return output ## Problem 10 def myUnion(L): output=set() for x in L: output=output | x return output
inverse_index_lab也比较简单:
from random import randint from dictutil import * ## Task 1 def movie_review(name): """ Input: the name of a movie Output: a string (one of the review options), selected at random using randint """ review_options = ["See it!", "A gem!", "Ideological claptrap!"] return review_options[randint(0,len(review_options)-1)] ## Tasks 2 and 3 are in dictutil.py ## Task 4 def makeInverseIndex(strlist): """ Input: a list of documents as strings Output: a dictionary that maps each word in any document to the set consisting of the document ids (ie, the index in the strlist) for all documents containing the word. Note that to test your function, you are welcome to use the files stories_small.txt or stories_big.txt included in the download. """ output={} for (i,x) in list(enumerate(strlist)): tmp=x.split() for word in tmp: if word in output: output[word]=output[word] | {i} else: output[word]={i} return output ## Task 5 def orSearch(inverseIndex, query): """ Input: an inverse index, as created by makeInverseIndex, and a list of words to query Output: the set of document ids that contain _any_ of the specified words """ output=set() for word in query: output=output | inverseIndex[word] return output ## Task 6 def andSearch(inverseIndex, query): """ Input: an inverse index, as created by makeInverseIndex, and a list of words to query Output: the set of all document ids that contain _all_ of the specified words """ output=set() if len(query)==0:return output output=inverseIndex[query[0]] for word in query: output=output & inverseIndex[word] return output
相关文章推荐
- Coding the Matrix Week 1 The vector 作业
- Coding the Matrix Week 3 The Matrix 矩阵
- 【Python】Coding the Matrix:Week 5: Dimension Homework 5
- Coding the Matrix Week 3 The Matrix 矩阵
- Coding the Matrix作业Python Lab及提交方法
- Coding the Matrix Week 1 The Vector Space作业
- Coding the Matrix Week 2 The Vector Space作业
- 【Python】Coding the Matrix:Week 5 Perspective Lab
- Coding the Matrix (3):矩阵
- 吴恩达深度学习课程deeplearning.ai课程作业:Class 4 Week 4 Face Recognition for the Happy House
- 作业week2 'Guess the number'
- Coding the Matrix (2):向量空间
- 作业Week3 "Stopwatch: The Game"
- Coding the Matrix (1):向量
- Coding the Matrix (0):映射、复数和域
- Cracking The Coding Interview 4.0_二叉树
- WEEK 8 JAVA作业
- setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key解决办法
- Week 19 算法理论作业(课后题目)
- Cracking the coding interview--Q20.2