当前位置: 首页 > news >正文

肥西县建设官方局网站网站自己服务器

肥西县建设官方局网站,网站自己服务器,中国室内设计网站排名,优化大师官网文章目录 一、代码仓库二、向量的基本运算2.1 加法2.2 数量乘法2.3 向量运算的基本性质2.4 零向量2.5 向量的长度2.6 单位向量2.7 点乘/内积#xff1a;两个向量的乘法 --答案是一个标量 三、手写Vector代码3.1 在控制台测试__repr__和__str__方法3.2 创建实例测试代码3.3 完整… 文章目录 一、代码仓库二、向量的基本运算2.1 加法2.2 数量乘法2.3 向量运算的基本性质2.4 零向量2.5 向量的长度2.6 单位向量2.7 点乘/内积两个向量的乘法 --答案是一个标量 三、手写Vector代码3.1 在控制台测试__repr__和__str__方法3.2 创建实例测试代码3.3 完整代码Vector.py_globals.pymain_vector.pymain_numpy_vector.py 一、代码仓库 https://github.com/Chufeng-Jiang/Python-Linear-Algebra-for-Beginner/tree/main 二、向量的基本运算 2.1 加法 2.2 数量乘法 2.3 向量运算的基本性质 2.4 零向量 2.5 向量的长度 2.6 单位向量 单位向量叫做 u hat 2.7 点乘/内积两个向量的乘法 --答案是一个标量 三、手写Vector代码 3.1 在控制台测试__repr__和__str__方法 3.2 创建实例测试代码 from playLA.Vector import Vectorif __name__ __main__:vec Vector([5, 2])print(vec)print(len(vec) {}.format(len(vec)))print(vec[0] {}, vec[1] {}.format(vec[0], vec[1]))3.3 完整代码 Vector.py import math from ._globals import EPSILON class Vector:def __init__(self, lst):__init__ 代表类的构造函数双下划线开头的变量 例如_values,代表类的私有成员lst是个引用list(lst)将值复制一遍防止用户修改值self._values list(lst)def dot(self, another):向量点乘返回结果标量assert len(self) len(another), \Error in dot product. Length of vectors must be same.return sum(a * b for a, b in zip(self, another))def norm(self):返回向量的模return math.sqrt(sum(e**2 for e in self))def normalize(self):归一化规范化返回向量的单位向量此处设计到了除法: def __truediv__(self, k):if self.norm() EPSILON:raise ZeroDivisionError(Normalize error! norm is zero.)return Vector(self._values) / self.norm()# return 1 / self.norm() * Vector(self._values)# return Vector([e / self.norm() for e in self])def __truediv__(self, k):返回数量除法的结果向量self / kreturn (1 / k) * selfclassmethoddef zero(cls, dim):返回一个dim维的零向量classmethod 修饰符对应的函数不需要实例化不需要 self 参数但第一个参数需要是表示自身类的cls参数可以来调用类的属性类的方法实例化对象等。return cls([0] * dim)def __add__(self, another):向量加法返回结果向量assert len(self) len(another), \Error in adding. Length of vectors must be same.# return Vector([a b for a, b in zip(self._values, another._values)])return Vector([a b for a, b in zip(self, another)])def __sub__(self, another):向量减法返回结果向量assert len(self) len(another), \Error in subtracting. Length of vectors must be same.return Vector([a - b for a, b in zip(self, another)])def __mul__(self, k):返回数量乘法的结果向量self * kreturn Vector([k * e for e in self])def __rmul__(self, k):返回数量乘法的结果向量k * selfself本身就是一个列表return self * kdef __pos__(self):返回向量取正的结果向量return 1 * selfdef __neg__(self):返回向量取负的结果向量return -1 * selfdef __iter__(self):返回向量的迭代器return self._values.__iter__()def __getitem__(self, index):取向量的第index个元素return self._values[index]def __len__(self):返回向量长度有多少个元素return len(self._values)def __repr__(self):打印显示Vector([5, 2])return Vector({}).format(self._values)def __str__(self):打印显示(5, 2)return ({}).format(, .join(str(e) for e in self._values))_globals.py # 包中的变量但是对包外不可见因此使用“_”开头 EPSILON 1e-8main_vector.py from playLA.Vector import Vectorif __name__ __main__:vec Vector([5, 2])print(vec)print(len(vec) {}.format(len(vec)))print(vec[0] {}, vec[1] {}.format(vec[0], vec[1]))vec2 Vector([3, 1])print({} {} {}.format(vec, vec2, vec vec2))print({} - {} {}.format(vec, vec2, vec - vec2))print({} * {} {}.format(vec, 3, vec * 3))print({} * {} {}.format(3, vec, 3 * vec))print({} {}.format(vec, vec))print(-{} {}.format(vec, -vec))zero2 Vector.zero(2)print(zero2)print({} {} {}.format(vec, zero2, vec zero2))print(norm({}) {}.format(vec, vec.norm()))print(norm({}) {}.format(vec2, vec2.norm()))print(norm({}) {}.format(zero2, zero2.norm()))print(normalize {} is {}.format(vec, vec.normalize()))print(vec.normalize().norm())print(normalize {} is {}.format(vec2, vec2.normalize()))print(vec2.normalize().norm())try:zero2.normalize()except ZeroDivisionError:print(Cannot normalize zero vector {}..format(zero2))print(点乘)print(vec.dot(vec2)) main_numpy_vector.py import numpy as npif __name__ __main__:print(np.__version__)# np.array 基础print(np.array 基础)lst [1, 2, 3]lst[0] Linear Algebraprint(lst)print(vec np.array([1, 2, 3]))vec np.array([1, 2, 3])print(vec)# vec[0] Linear Algebra# vec[0] 666# print(vec)print(np.array的创建)# np.array的创建print(np.zeros(5))print(np.ones(5))print(np.full(5, 666))print(np.array的基本属性)# np.array的基本属性print(vec)print(size , vec.size)print(size , len(vec))print(vec[0])print(vec[-1])print(vec[0: 2])print(type(vec[0: 2]))print(np.array的基本运算)# np.array的基本运算vec2 np.array([4, 5, 6])print({} {} {}.format(vec, vec2, vec vec2))print({} - {} {}.format(vec, vec2, vec - vec2))print({} * {} {}.format(2, vec, 2 * vec))print(没有数学意义的乘法{} * {} {}.format(vec, vec2, vec * vec2))print({}.dot({}) {}.format(vec, vec2, vec.dot(vec2)))print(求模)print(np.linalg.norm(vec))print(归一化)print(vec / np.linalg.norm(vec))print(单位向量)print(np.linalg.norm(vec / np.linalg.norm(vec)))print(零向量会报错)zero3 np.zeros(3)print(zero3 / np.linalg.norm(zero3))
http://www.yutouwan.com/news/278393/

相关文章:

  • vs做网站需要的插件wordpress设置用户头像
  • 个人申请网站福州快速优化排名
  • 中国室内设计联盟网站网站建设基本
  • 程序员给女盆友做的网站主机搭建网站教程
  • 上海工程建设协会网站网站建设与运营 pdf
  • 北京市规划网站做任务挣钱的网站app
  • 网站优化软件推荐wordpress 首页静态
  • 开发东莞网站制作公司织梦怎么做手机网站
  • 青岛网站建设公司排行陕西省高速集团建设网站
  • 西安家政公司网站建设成都微信小程序
  • 免费做电子章网站廊坊首位关键词优化电话
  • 网站开发形象设计要求百度地图关键词优化
  • 网站服务器租用资质松江建设网站公司
  • 网站搬家到Wordpress网络公司主要做哪些
  • 重庆建个网站需要多少钱?建一个网站大概多少钱
  • 酒店网站免费建设asp网站伪静态页面
  • nodejs 做网站js交件wordpress子主题安装
  • 怎么样网站速度快龙岩市网站建设
  • 企业网站seo报价wordpress主题解密
  • 网站开发面试问题网站seo搜索引擎优化怎么做
  • 宜昌网站开发公司南通启益建设集团有限公司网站
  • wordpress建企业站教程开发手游
  • 网站数据库如何做做网站生意多吗
  • 用什么软件做网站最好网站建设公司专业网站费用报价
  • 智加设计公司企业seo的措施有哪些
  • 手机网站模板 网址焦作维科网站建设公司
  • 网站维护与推广做网站大约需要多少钱
  • asp.net 网站授权免费的网站推广怎么做效果好
  • 手机做点击赚钱的网站seosem推广
  • 网站浏览器wordpress制作轮播图