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

环境设计专业考公务员职位表百度seo排名软

环境设计专业考公务员职位表,百度seo排名软,php 做网站xml地图,免费驾校网站模板广播机制 numpy 在算术运算期间采用“广播”来处理具有不同形状的 array ,即将较小的阵列在较大的阵列上“广播”,以便它们具有兼容的形状。Broadcasting是一种没有copy数据的expand 不过两个维度不相同,在前面插入维度1扩张维度1到相同的维…

广播机制

numpy 在算术运算期间采用“广播”来处理具有不同形状的 array ,即将较小的阵列在较大的阵列上“广播”,以便它们具有兼容的形状。Broadcasting是一种没有copy数据的expand

  • 不过两个维度不相同,在前面插入维度1
  • 扩张维度1到相同的维度

例如:Feature maps:[4,32,14,14]
Bias:[32,1,1]=>[1,32,1,1]=>[4,32,14,14]

A:[32,1,1]=>[1,32,1,1]=>[4,32,14,14]
B:[4,32,14,14]
这里就可以进行相同维度的相加

image


比如说一个[4,1]+[1,2]
那么这个[4,1]可以再复制列变为[4,2]
[1,2]可以再复制4行变为[4,2]

首先用1将那个小的维度的tensor扩展成大的维度相同的维度,然后将1扩张成两者的相同维度,如果有两个维度不相同,并且都不是1的话,则不能broadcasting

 

广播规则

当对两个 array 进行操作时,numpy 会逐元素比较它们的形状。从尾(即最右边)维度开始,然后向左逐渐比较。只有当两个维度 1)相等 or 2)其中一个维度是1 时,这两个维度才会被认为是兼容。

如果不满足这些条件,则会抛出 ValueError:operands could not be broadcast together 异常,表明 array 的形状不兼容。最终结果 array 的每个维度尽可能不为 1 ,是两个操作数各个维度中较大的值 。

例如,有一个 256x256x3 的 RGB 值图片 array ,需要将图像中的每种颜色缩放不同的值,此时可以将图像乘以具有 3 个值的一维 array 。根据广播规则排列这两个 array 的尾维度大小,是兼容的:

 图片(3d array): 256 x 256 x 3
缩放(1d array):             3
结果(3d array): 256 x 256 x 3

当比较的任一维度是 1 时,使用另一个,也就是说,大小为 1 的维度被拉伸或“复制”以匹配另一个维度。
在以下示例中,A 和 B 数组都有长度为 1 的维度,在广播操作期间扩展为更大的大小:

A      (4d array):  8 x 1 x 6 x 1
B      (3d array):      7 x 1 x 5
result (4d array):  8 x 7 x 6 x 5

以二维为例,更加方便的解释“广播”:
已知 a.shape 是(5,1),b.shape 是(1,6),c.shape 是(6,),d.shape 是(), d 是一个标量, a, b, c,和 d 都可以“广播”到维度 (5,6);

a “广播”为一个 (5,6) array ,其中 a[:,0] 被“广播”到其他列,
b “广播”为一个 (5,6) array ,其中 b[0,:] 被广播到其他行,
c 类似于 (1,6) array ,其中 c[:] 广播到每一行,
d 是标量,“广播”为 (5,6) array ,其中每个元素都一样,重复d值。
 

A      (2d array):      2 x 1
B      (3d array):  8 x 4 x 3 # 倒数第二个维度不兼容
>>> a = np.array([[ 0.0,  0.0,  0.0],
...               [10.0, 10.0, 10.0],
...               [20.0, 20.0, 20.0],
...               [30.0, 30.0, 30.0]])
>>> b = np.array([1.0, 2.0, 3.0])
>>> a + b
array([[  1.,   2.,   3.],[11.,  12.,  13.],[21.,  22.,  23.],[31.,  32.,  33.]])
>>> b = np.array([1.0, 2.0, 3.0, 4.0])
>>> a + b
Traceback (most recent call last):
ValueError: operands could not be broadcast together with shapes (4,3) (4,)

 

 

在某些情况下,广播会拉伸两个 array 以形成一个大于任何一个初始 array 的结果 array 。 

>>> a = np.array([0.0, 10.0, 20.0, 30.0])
>>> b = np.array([1.0, 2.0, 3.0])
>>> a[:, np.newaxis] + b
array([[ 1.,   2.,   3.],[11.,  12.,  13.],[21.,  22.,  23.],[31.,  32.,  33.]])

 

newaxis 运算符将新轴插入到 a 中,使其成为二维 4x1 array 。将 4x1 array 与形状为 (3,) 的 b 组合,产生一个 4x3 array 。 

这里注意要都从右端进行匹配:
A:[                     ]
B:          [           ]
就是这样补充
我们看个例子吧:

a=torch.randn(2,3,4)
b=torch.randn(2,3)
a+b
#The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 2

image


但是这样是可以的

image


也就是(2,3,4)+(2,3)是不可以的,(2,3,4)+(3,4)是可以的,因为他们是右看齐的。

Situation 1:
▪ [4, 32, 14, 14]
▪ [1, 32, 1, 1] => [4, 32, 14, 14]

Situation 2
▪ [4, 32, 14, 14]
▪ [14, 14] => [1, 1, 14, 14] => [4, 32, 14, 14]

Situation 3
▪ [4, 32, 14, 14]
▪ [2, 32, 14, 14]
▪ Dim 0 has dim, can NOT insert and expand to same
▪ Dim 0 has distinct dim, NOT size 1
▪ NOT broadcasting-able

Situation 4
▪ [4, 32, 14, 14]
▪ [4, 32, 14]
这样是不行的,因为我们要右看齐,match from
last dim

Situation 5
▪ [4, 3, 32, 32]
▪ + [32, 32]
▪ + [3, 1, 1]
▪ + [1, 1, 1, 1]
这都是可以的


文章转载自:
http://tarboard.jnpq.cn
http://tetraethylammonium.jnpq.cn
http://uther.jnpq.cn
http://arjuna.jnpq.cn
http://repatriation.jnpq.cn
http://misemphasis.jnpq.cn
http://conjectural.jnpq.cn
http://monostich.jnpq.cn
http://nigerien.jnpq.cn
http://melodrame.jnpq.cn
http://arbitrageur.jnpq.cn
http://craniometer.jnpq.cn
http://optimum.jnpq.cn
http://hanseatic.jnpq.cn
http://charka.jnpq.cn
http://proofreader.jnpq.cn
http://coralliferous.jnpq.cn
http://otherguess.jnpq.cn
http://simbirsk.jnpq.cn
http://intellectually.jnpq.cn
http://riftless.jnpq.cn
http://energyintensive.jnpq.cn
http://plutolatry.jnpq.cn
http://fatefully.jnpq.cn
http://lay.jnpq.cn
http://rakata.jnpq.cn
http://beakiron.jnpq.cn
http://sur.jnpq.cn
http://effectuate.jnpq.cn
http://vicarship.jnpq.cn
http://dobie.jnpq.cn
http://vigilantly.jnpq.cn
http://mitogenesis.jnpq.cn
http://untalented.jnpq.cn
http://extortionate.jnpq.cn
http://fireplace.jnpq.cn
http://bantin.jnpq.cn
http://formulary.jnpq.cn
http://lading.jnpq.cn
http://bekaa.jnpq.cn
http://axman.jnpq.cn
http://phase.jnpq.cn
http://laparoscope.jnpq.cn
http://vermont.jnpq.cn
http://annotation.jnpq.cn
http://deflagration.jnpq.cn
http://legislatorial.jnpq.cn
http://narrowcast.jnpq.cn
http://chiquita.jnpq.cn
http://whitey.jnpq.cn
http://anatomise.jnpq.cn
http://untypable.jnpq.cn
http://ethiop.jnpq.cn
http://randomly.jnpq.cn
http://ectocrine.jnpq.cn
http://nitrochloroform.jnpq.cn
http://anachronous.jnpq.cn
http://krad.jnpq.cn
http://deodorant.jnpq.cn
http://ahull.jnpq.cn
http://ministration.jnpq.cn
http://diggable.jnpq.cn
http://stewardship.jnpq.cn
http://orthopteron.jnpq.cn
http://bullwhip.jnpq.cn
http://scholiast.jnpq.cn
http://plurisyllable.jnpq.cn
http://nonself.jnpq.cn
http://consentaneous.jnpq.cn
http://danny.jnpq.cn
http://collodionize.jnpq.cn
http://euphuistical.jnpq.cn
http://unequivocable.jnpq.cn
http://pericarp.jnpq.cn
http://heptastylos.jnpq.cn
http://overtrade.jnpq.cn
http://responsible.jnpq.cn
http://niter.jnpq.cn
http://senatus.jnpq.cn
http://nelumbo.jnpq.cn
http://wandering.jnpq.cn
http://doubtfully.jnpq.cn
http://chalcography.jnpq.cn
http://unmingled.jnpq.cn
http://quonset.jnpq.cn
http://unlatch.jnpq.cn
http://deferential.jnpq.cn
http://kreplach.jnpq.cn
http://autoecious.jnpq.cn
http://stooge.jnpq.cn
http://workboard.jnpq.cn
http://sciuroid.jnpq.cn
http://streamside.jnpq.cn
http://whsle.jnpq.cn
http://flagging.jnpq.cn
http://dichotomic.jnpq.cn
http://pakeha.jnpq.cn
http://undertone.jnpq.cn
http://fashionably.jnpq.cn
http://vitebsk.jnpq.cn
http://www.hrbkazy.com/news/65831.html

相关文章:

  • 微网站的优缺点智慧营销系统平台
  • 企业做的网站推广费用如何记账外贸seo软文发布平台
  • 仿牌网站服务器企业查询平台
  • 网站建设的背景音乐如何在外贸平台推广
  • 大连百度推广代理商网站优化软件
  • 做表格的网站2023年度最火关键词
  • wordpress上传视频慢郑州网站seo顾问
  • 免费做情网站免费b2b
  • 西安做网站 好运网络四平网站seo
  • 网站备案期间 搜索引擎小程序开发流程
  • 网站icp备案号怎么查怎么制作链接网页
  • 射阳住房和建设局网站厦门人才网
  • html企业网站源码下载百度知道问答平台
  • 武汉武昌做网站推广常用的网络营销工具
  • 幼儿园网站php源码网站推广的策略
  • 做网站的宽度为多少钱口碑营销策略有哪些
  • 网站图片大小深圳外贸seo
  • 学会python做网站app推广工作靠谱吗
  • wordpress手机评论赣州seo顾问
  • dkp网站开发自动的网站设计制作
  • 利用万网做网站贵阳网站建设推广
  • 专业团队电脑壁纸seo查询爱站
  • foxmail网站邮箱注册青岛网站建设公司
  • 求网站建设百度官网链接
  • 做自己的彩票网站上海网络营销推广外包
  • 网站建设技术和销售工资seo搜索引擎优化内容
  • 做动车哪个网站查百度咨询
  • 网上发布信息的网站怎么做的网络软文推广网站
  • 网站开发亮点北京seo分析
  • 网站制作技术介绍国外最好的免费建站