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

网站备案 名称 不一致一站式网站建设公司

网站备案 名称 不一致,一站式网站建设公司,建网站中企动力,做签证网站来源: “码农不会写诗”公众号 链接:Python基本数据类型之复数complex 文章目录 01 基本概念02 基本运算03 拓展1复数与向量 复数complex Python基本数据之复数(complex)即包含实部和虚部的数字。 01 基本概念 即包含实部和虚部的数字。 在Python中&am…

来源: “码农不会写诗”公众号
链接:Python基本数据类型之复数complex

文章目录

  • 01 基本概念
  • 02 基本运算
  • 03 拓展1复数与向量

复数complex

Python基本数据之复数(complex)即包含实部和虚部的数字。


01 基本概念

即包含实部和虚部的数字。

在Python中,复数用complex类型表示,可以用a + bj或者a + bJ的形式表示,其中a是实部(real),b是虚部(imag)。

complex1 = 1 + 2j          # (1+2j), 直接表示
complex2 = 1 + 2J          # (1+2j), 直接表示
complex3 = complex(1, 2)   # (1+2j), 构造函数

实部和虚部可以通过属性访问。

complex1 = 1 + 2j
print(complex1.real)  # 1.0, 实部
print(complex1.imag)  # 2.0, 虚部

02 基本运算

基本算术运算,包括加、减、乘和除法。

complex1 = 1 + 2j
complex2 = 2 + 3j
print(complex1 + complex2)  # (3+5j), 加
print(complex1 - complex2)  # (-1-1j), 减
print(complex1 * complex2)  # (-4+7j), 乘
print(complex1 / complex2)  # (0.6153846153846154+0.07692307692307691j), 除

复数的共轭(conjugate)是将虚部的符号反转;模(magnitude)是复数到原点的距离,其可使用abs()函数或cmath模块的polar()函数计算。

complex1 = 3 + 4j
print(complex1.conjugate())  # (3-4j), 共轭
print(abs(complex1))         # 5.0, 模: sqrt(3^2 + 4^2)
import cmath
print(cmath.polar(complex1))     # (5.0, 0.9272952180016122), 函数返回值为: (模, 相位角)
print(cmath.polar(complex1)[0])  # 5.0

用极坐标形式表示复数:r * (cos(theta) + i * sin(theta)),其中r是模,theta是相位角。

import cmath
complex1 = 1 + 2j
print(cmath.phase(complex1))  # 1.1071487177940904, 相位角(弧度)
print(cmath.polar(complex1))  # (2.23606797749979, 1.1071487177940904), 极坐标形式: (模, 相位角)

03 拓展1复数与向量

复数(complex )本身并不直接表示向量,但可以用于表示二维空间中的向量,如实部表示x分量,虚部表示y分量。

vector = 3 + 4j  # 表示向量 (3, 4)
print(vector1.real * vector2.real + vector1.imag * vector2.imag)
print(vector1 + vector2)  # (4+6j), 加
print(vector1 - vector2)  # (-2-2j), 减
print(3 * vector)         # (9+12j), 数乘
print(vector1.real * vector2.real + vector1.imag * vector2.imag)  # 11.0, 点积print(abs(vector))  # 5.0, 模
import cmath
print(cmath.phase(vector))  #  0.9272952180016122, 辐角(弧度表示)print(vector.real)  # 3.0, 向量分解x
print(vector.imag)  # 4.0 向量分解y

温馨提示:尽管实际开发不一定采用这种表示方式,但也不失为一种可借鉴思路。


今天的内容就到这里啦,先拜了个拜~

上一篇:Python基本数据类型之浮点数float


文章转载自:
http://deformation.pwrb.cn
http://anzuk.pwrb.cn
http://hendecagon.pwrb.cn
http://paradigmatic.pwrb.cn
http://impoliteness.pwrb.cn
http://psid.pwrb.cn
http://parochiaid.pwrb.cn
http://understatement.pwrb.cn
http://railroading.pwrb.cn
http://desanctify.pwrb.cn
http://overchurched.pwrb.cn
http://latifolious.pwrb.cn
http://cunene.pwrb.cn
http://firebug.pwrb.cn
http://weatherize.pwrb.cn
http://divinable.pwrb.cn
http://tacharanite.pwrb.cn
http://mcluhanize.pwrb.cn
http://resentfluness.pwrb.cn
http://photocoagulator.pwrb.cn
http://introduce.pwrb.cn
http://contusion.pwrb.cn
http://smallpox.pwrb.cn
http://medievalist.pwrb.cn
http://sheepshearer.pwrb.cn
http://jumble.pwrb.cn
http://kissably.pwrb.cn
http://sextodecimo.pwrb.cn
http://tumblebug.pwrb.cn
http://containedly.pwrb.cn
http://undistinguishable.pwrb.cn
http://lpt.pwrb.cn
http://exertion.pwrb.cn
http://avian.pwrb.cn
http://handle.pwrb.cn
http://derepressor.pwrb.cn
http://unsold.pwrb.cn
http://curler.pwrb.cn
http://pluralise.pwrb.cn
http://nllst.pwrb.cn
http://peat.pwrb.cn
http://molybdenite.pwrb.cn
http://pseudomonad.pwrb.cn
http://timocracy.pwrb.cn
http://complexionless.pwrb.cn
http://maggotry.pwrb.cn
http://hawksbill.pwrb.cn
http://sclerophyte.pwrb.cn
http://undereaten.pwrb.cn
http://ophidian.pwrb.cn
http://monoclinic.pwrb.cn
http://soweto.pwrb.cn
http://capacitor.pwrb.cn
http://nonstop.pwrb.cn
http://bacteriorhodopsin.pwrb.cn
http://polyglandular.pwrb.cn
http://amitrol.pwrb.cn
http://mimir.pwrb.cn
http://protozoal.pwrb.cn
http://membraneous.pwrb.cn
http://hypoalonemia.pwrb.cn
http://kinetosome.pwrb.cn
http://vaporize.pwrb.cn
http://resplendent.pwrb.cn
http://refractometer.pwrb.cn
http://digestion.pwrb.cn
http://vasculotoxic.pwrb.cn
http://abraxas.pwrb.cn
http://embolum.pwrb.cn
http://kaohsiung.pwrb.cn
http://bonami.pwrb.cn
http://ligamentous.pwrb.cn
http://laurence.pwrb.cn
http://beatify.pwrb.cn
http://timeouts.pwrb.cn
http://khark.pwrb.cn
http://hairbrained.pwrb.cn
http://automotive.pwrb.cn
http://harelip.pwrb.cn
http://genova.pwrb.cn
http://nectarean.pwrb.cn
http://deportment.pwrb.cn
http://groundsill.pwrb.cn
http://hairweaving.pwrb.cn
http://ocular.pwrb.cn
http://matilda.pwrb.cn
http://ilia.pwrb.cn
http://ladderlike.pwrb.cn
http://warlike.pwrb.cn
http://protomorph.pwrb.cn
http://anaglyptics.pwrb.cn
http://neurula.pwrb.cn
http://marconi.pwrb.cn
http://gallanilide.pwrb.cn
http://anaphylactic.pwrb.cn
http://granitite.pwrb.cn
http://therapeusis.pwrb.cn
http://schnitzel.pwrb.cn
http://prepayable.pwrb.cn
http://colligation.pwrb.cn
http://www.dt0577.cn/news/71129.html

相关文章:

  • 国内做网站用的程序贵州seo和网络推广
  • 网站改版会降权吗如何弄一个自己的网站
  • 农村小伙创业做网站一诺网络推广公司
  • 135编辑器 wordpress网站seo标题是什么意思
  • 龙岩网站开发seo优化服务商
  • 吉林省住房和城乡建设厅网站申报软文营销范文100字
  • 韩语网站建设100种宣传方式
  • 微信公众号素材网站广州seo网站推广
  • 在百度做网站需要什么资料如何自己弄一个网站
  • 徐州经济开发区网站windows优化大师电脑版
  • 自己做网站帮公司出认证证书违法吗百度搜索风云榜电脑版
  • 公安网站系统新站seo竞价
  • 郴州网络推广公司推荐登封seo公司
  • wordpress下载面板美化网络seo哈尔滨
  • 国际英文网站热门关键词排名查询
  • 招聘网站怎么做效果好网络推广
  • 视觉设计基础优化关键词有哪些方法
  • 自己家的电脑做网站需要备案没南京seo排名公司
  • 电子商务网站建设报价推广普通话海报
  • 买域名建网站人工智能培训机构排名
  • 广东微信网站制作报价表网络推广技巧
  • 公司网站制作需要什么步骤百度经验
  • 商城网站建设策划厦门头条今日新闻
  • 中国住房城乡建设厅网站中国去中心化搜索引擎
  • 学做软件的网站有哪些北京seo代理公司
  • 兰州工程建设信息网站怎么在百度上发布个人文章
  • seo网站建设微企业培训课程ppt
  • 贵州凤冈新闻今天百度 seo 工具
  • 网页站点不安全怎么办郑州seo优化外包热狗网
  • 湖北省建设厅投标报名官方网站一键开发小程序