Coding the Matrix: Linear Algebra through Computer Science Applications

本周的作业较少,只有一个编程任务hw2.作业比较简单,如果大学学习过矩阵代数的话,基本上没有什么问题,不过要注意的一点是基2的Span的求法。

基2空间上,在所有基向量中取任意个数个,叠加组合就得到了Span。但是如何取任意个呢?下面给出几种方法。

一种方法是对于任意可能的个数,利用Python中的排列组合module生成对应于此个数的所有排列,即得到Span。感兴趣的话可以百度一下。这种方法概念较为清晰,但需要对Python的库较为了解。

第二种方法,利用了从n个元素中任选任意个的方法只有2^n个的排列组合知识。具体来说,就是对于任意从0到2^n-1的整数,使用bin()函数得到其二进制表示,对应位为1即代表选中此基向量。这种方法稍微Smart一些。但过程较为冗杂。

第三种,就是下面程序给出的方法,一行语句就可以完成运算,原理和上一种方法相同,就不再赘述。但要注意结果为0的情况下要单独考虑。

其他的向量运算都比较简单,最后几道判断是否为向量空间的问题,只需要牢记向量空间三特征(包含0,加减和向量乘法组合仍在空间内)就不会出错。

作业代码如下,模版中注释部分给出了验证范例。

# version code 761
# Please fill out this stencil and submit using the provided submission script.from vec import Vec
from GF2 import one## Problem 1
def vec_select(veclist, k): '''>>> D = {'a','b','c'}>>> v1 = Vec(D, {'a': 1})>>> v2 = Vec(D, {'a': 0, 'b': 1})>>> v3 = Vec(D, {        'b': 2})>>> v4 = Vec(D, {'a': 10, 'b': 10})>>> vec_select([v1, v2, v3, v4], 'a') == [Vec(D,{'b': 1}), Vec(D,{'b': 2})]True'''return [x for x in veclist if x[k]==0]def vec_sum(veclist, D): '''>>> D = {'a','b','c'}>>> v1 = Vec(D, {'a': 1})>>> v2 = Vec(D, {'a': 0, 'b': 1})>>> v3 = Vec(D, {        'b': 2})>>> v4 = Vec(D, {'a': 10, 'b': 10})>>> vec_sum([v1, v2, v3, v4], D) == Vec(D, {'b': 13, 'a': 11})True'''return sum(veclist) if len(veclist)!=0 else Vec(D,{})def vec_select_sum(veclist, k, D): '''>>> D = {'a','b','c'}>>> v1 = Vec(D, {'a': 1})>>> v2 = Vec(D, {'a': 0, 'b': 1})>>> v3 = Vec(D, {        'b': 2})>>> v4 = Vec(D, {'a': 10, 'b': 10})>>> vec_select_sum([v1, v2, v3, v4], 'a', D) == Vec(D, {'b': 3})True'''return vec_sum(vec_select(veclist,k),D)## Problem 2
def scale_vecs(vecdict):'''>>> v1 = Vec({1,2,3}, {2: 9})>>> v2 = Vec({1,2,4}, {1: 1, 2: 2, 4: 8})>>> scale_vecs({3: v1, 5: v2}) == [Vec({1,2,3},{2: 3.0}), Vec({1,2,4},{1: 0.2, 2: 0.4, 4: 1.6})]True'''return [y/x for (x,y) in vecdict.items()]## Problem 3
def GF2_span(D, L):'''>>> from GF2 import one>>> D = {'a', 'b', 'c'}>>> L = [Vec(D, {'a': one, 'c': one}), Vec(D, {'b': one})]>>> len(GF2_span(D, L))4>>> Vec(D, {}) in GF2_span(D, L)True>>> Vec(D, {'b': one}) in GF2_span(D, L)True>>> Vec(D, {'a':one, 'c':one}) in GF2_span(D, L)True>>> Vec(D, {x:one for x in D}) in GF2_span(D, L)True'''if len(L)==0:return []maxind=2**len(L)-1res=[sum([L[j] for j in range(len(L)) if i//(2**j)%2]) for i in range(maxind+1)]res.append(Vec(D,{}))del res[0]return res## Problem 4
# Answer with a boolean, please.is_it_a_vector_space_1 = True
is_it_a_vector_space_2 = False## Problem 5
is_it_a_vector_space_3 = True
is_it_a_vector_space_4 = False## Problem 6is_it_a_vector_space_5 = True
is_it_a_vector_space_6 = False

Coding the Matrix Week 1 The Vector Space作业相关推荐

  1. Coding the Matrix Week 2 The Vector Space作业

    Coding the Matrix: Linear Algebra through Computer Science Applications 本周的作业较少,只有一个编程任务hw2.作业比较简单,如 ...

  2. Coding the Matrix Week 1 The vector 作业

    Coding the Matrix: Linear Algebra through Computer Science Applications 这次作业难度不小,第一个作业hw1还好,第二个全部都可以 ...

  3. Vector space

    In mathematics and physics, a vector space (also called a linear space) is a set whose elements, oft ...

  4. nlp论文——《Efficient Estimation of Word Representations in Vector Space》(向量空间中词表示的有效估计)

    目录 <Efficient Estimation of Word Representations in Vector Space> 第一课时:论文导读 (1)语言模型 (2)词向量简介-- ...

  5. Coding the Matrix Week 0 作业

    Coding the Matrix: Linear Algebra through Computer Science Applications 本次作业分成三部分,第一部分点击打开链接 已经记录过,后 ...

  6. Coding the Matrix作业Python Lab及提交方法

    Coding the Matrix: Linear Algebra through Computer Science Applications 这是一门用python实现矩阵运算的课,第一次作业就感觉 ...

  7. dual vector space

    for the concepts of vector space and field, please refer to http://blog.csdn.net/seamanj/article/det ...

  8. 数学基础 - 线性空间(Vector Space)

    线性空间(Vector Space) 定义(Definition) 设V是一个非空集合,P是一个域: 加法: ∀α,β∈V ∀ α , β ∈ V \forall \; \alpha,\beta \i ...

  9. 论文翻译解读:Efficient estimation of word representations in vector space【Word2Vec】

    文章目录 简要信息 重点内容概括 Efficient estimation of word representations in vector space 摘要 1 介绍 1.1 论文目标 1.2 以 ...

最新文章

  1. 德州农工大学 计算机排名,德州农工大学美国大学排名及专业排名汇总(USNEWS美国大学排名版)...
  2. 如何用java完成Excel快速的导入导出
  3. SQL server 实例教程
  4. [pytorch、学习] - 9.2 微调
  5. bzoj千题计划241:bzoj3864: Hero meet devil
  6. word List 13
  7. graphpad数据小数点_GraphPad Prism 统计指南 | 关于异常值(Outlier),你真的了解吗?...
  8. django使用iframe
  9. 软件概要设计_软件测试模型之 V模型
  10. MyCAT-1.4-RC基准测试
  11. Tcl 语言——过程与字符串匹配篇
  12. 苹果视频剪辑计算机配置,视频剪辑后期神器-创作PC黑苹果系统安装与台式电脑配置推荐...
  13. 原始套接字Raw Socket基础-- WSADATA wsaData(转)
  14. 永中office属于职称计算机吗,永中office
  15. 微信小程序 | 微信公众平台SpringBoot开发实例 │ 表情消息
  16. 宇视科技设备SDK获取方式
  17. Matlab实现蚂蚁群算法
  18. 餐饮SaaS行进时:美团To B,二维火To C
  19. PMP项目管理—质量情景题
  20. LM7805使用总结

热门文章

  1. 强大的DataGrid组件[4]_实现CURD[上]——Silverlight学习笔记[12]
  2. win10家庭版无法安装mysql_Win10安装MySQL
  3. java excel类库_Java 操作 Excel 的类库 jExcelApi
  4. string是python内置函数吗_Python 字符串与内置函数(方法)
  5. 导数与微分的知识点思维导图_高中物理思维导图,高中三年知识点一个不漏
  6. go 判断是否域名_Go编程:对不起,你的 CPU 泄露了
  7. 哲学系列:《老子的智慧》、《吾国与吾民》、《从异教徒到基督教徒》、《佛教的精神与特色》、《禅与摩托车维修技术》、《人生的智慧》等读书笔记...
  8. java 清屏_【图片】请问java编写中如何做到清屏啊。。。_java吧_百度贴吧
  9. python数据建模工具_python数据分析工具——Pandas、StatsModels、Scikit-Learn
  10. Matlab条形图bar横坐标间距设置