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

橙 建网站网站建设范围

橙 建网站,网站建设范围,哪个网站容易做二级域名,做网站是买服务器还是买主机本次将介绍一下 Tensor 张量常用的索引与切片的方法#xff1a; 1. index 索引 index 索引值表示相应维度值的对应索引 a torch.rand(4, 3, 28, 28) print(a[0].shape) # 返回维度一的第 0 索引 tensor print(a[0, 0].shape) # 返回维度一 0 索引位置…本次将介绍一下 Tensor 张量常用的索引与切片的方法 1. index 索引 index 索引值表示相应维度值的对应索引 a torch.rand(4, 3, 28, 28) print(a[0].shape) # 返回维度一的第 0 索引 tensor print(a[0, 0].shape) # 返回维度一 0 索引位置维度二 0 索引位置的 tensor print(a[0, 0, 0].shape) # 返回维度一 0 索引维度二 0 索引维度三 0索引的 tensor print(a[0, 0, 2, 4].shape) # 返回维度一 0 索引维度二 0 索引维度三 2索引维度四 4索引位置的 tensor (dim 0) print(a[0, 0, 2, 4])# 输出结果 torch.Size([3, 28, 28]) torch.Size([28, 28]) torch.Size([28]) torch.Size([]) tensor(0.4504)2. select first/last N 返回前 N 个或后 N 个的 tensor 【:】表示该维度所有值 【:2】表示从索引 0 开始到索引 2 的值包首不包尾 【1:】表示索引 1 开始到最后 【-2:】表示倒数第二个值到最后 【…】表示一个或几个维度不变 a torch.rand(4, 3, 28, 28) print(a[:2].shape) # 返回维度一索引 0 ~ 2 的 tensor相当于 a[:2, :, :, :].shape, : 表示都选择 print(a[:2, :1, :, :].shape) # 返回维度一索引 0 ~ 2维度二索引 0 ~ 1 的 tensor print(a[:2, :1, :3, :4].shape) # 返回维度一索引 0 ~ 2维度二索引 0 ~ 1维度三索引 0 ~ 3维度四索引 0 ~ 4 的 tensor print(a[:2, 1:, :, :].shape) # 返回维度一索引 0 ~ 2维度二索引 1 ~ 3 的 tensor print(a[:2, -2:, :, :].shape) # 返回维度一索引 0 ~ 2维度二索引 1 ~ 3 的 tensor# ---------【...】的应用 -------------- print(a[...].shape) # 表示返回一样的 a print(a[0, ...].shape) # 表示返回维度一索引 0 位置的 tensor print(a[:, 1, ...].shape) # 表示返回维度二索引 1 位置的 tensor print(a[:, :, 2, ...].shape) # 表示返回维度三索引 2 位置的 tensor print(a[..., 10].shape) # 表示返回维度四索引 10 位置的 tensor print(a[..., :2].shape) # 表示返回维度四索引 0 ~2 数量的 tensor# 输出结果 torch.Size([2, 3, 28, 28]) torch.Size([2, 1, 28, 28]) torch.Size([2, 1, 3, 4]) torch.Size([2, 2, 28, 28]) torch.Size([2, 2, 28, 28])# ---------【...】的应用的输出结果 -------------- torch.Size([4, 3, 28, 28]) torch.Size([3, 28, 28]) torch.Size([4, 28, 28]) torch.Size([4, 3, 28]) torch.Size([4, 3, 28]) torch.Size([4, 3, 28, 2])3. select by steps 按一定的间隔 steps 返回 tensor 【0:28:2】表示从索引 0 开始到 28间隔 2 取数所以为 14 有二个冒号便是按一定间隔取 a torch.rand(4, 3, 28, 28) print(a[:, :, 0:28:2, 0:28:4].shape)#输出结果 torch.Size([4, 3, 14, 7])4. index_select(intputTensor, dim, indexTensor) 根据输入的 inputTensor 按指定的维度索引 dim返回与 indexTensor 一样的 size其它维度不变的新 tensor a torch.rand(4, 3, 28, 28) b a.index_select(2, torch.arange(8)) # 也可以 inputTensor 直接调用 c torch.index_select(a, 2, torch.arange(8)) # 建议用这种形式返回 a 第 3 个维度与 torch.arange(8)一样 size 其它维度不变的新 tensor print(b.shape) print(c.shape)# 输出结果 torch.Size([4, 3, 8, 28]) torch.Size([4, 3, 8, 28]) 5. masked_select(intputTensor, maskTensor) 返回一个满足 maskTensor 条件的一维 tensor a torch.rand(3, 4) print(a) x a.ge(0.5) # 大于 0.5 的 bool 张量 print(x) print(a.masked_select(x)) # 返回值大于 0.5 的一维张量 print(torch.masked_select(a, x)) # 和上面一样但建议用这种形式# 输出结果 tensor([[0.0169, 0.1965, 0.7381, 0.9250],[0.8292, 0.2519, 0.1531, 0.8987],[0.1365, 0.4650, 0.4005, 0.7589]]) tensor([[False, False, True, True],[ True, False, False, True],[False, False, False, True]]) tensor([0.7381, 0.9250, 0.8292, 0.8987, 0.7589]) tensor([0.7381, 0.9250, 0.8292, 0.8987, 0.7589]) 6. take(inputTensor, indexTensor) 根据一维的索引张量 indexTensor返回一个新的一维 tensorinputTensor 看成是一维的。 a src torch.tensor([[4, 3, 5],[6, 7, 8]]) print(a.size()) b torch.tensor([0, 2, 5]) # 如 0 -- 4, 2 -- 5, 5 -- 8 c torch.take(a, b) print(c) print(c.size())# 输出结果 torch.Size([2, 3]) tensor([4, 5, 8]) torch.Size([3]) 总结涉及到索引就会存在索引越界的常见问题如下所示在使用的时候要注意一下。 IndexError: index 29 is out of bounds for dimension 1 with size 28 有不足之处欢迎一起交流学习
http://www.w-s-a.com/news/387046/

相关文章:

  • 南漳网站开发上海网站推广方法
  • 深圳seo网站大连旅顺房价
  • dede网站 地图什么做有没有做黑市网站
  • 做网站参考文献域名如何做网站
  • 怎么选择网站开发英文网站建设用途
  • 怎样做电子商务网站织梦生成手机网站
  • 公司网站建设选什么服务器网站里怎样添加关键词
  • 深圳建设局网站深业中城绿化项目营销型网站开发流程包括
  • 找销售的网站九江市建设项目服务中心
  • 东原ARC网站建设公司合肥seo网站推广外包
  • 那个网站是做房产中介的网站制作软件小学
  • 做网页怎么建站点视频解析网站
  • 做网站的系统设计网站设计论文前言
  • 做外贸网站多久更新汕头市建设局网站首页
  • 如何建设专业化的网站手机管理网站模板
  • 花生壳做网站如何用腾讯云做网站
  • 搭建集团网站开发app需要哪些软件
  • 网站建设 中企动力福州阀门wordpress 多说评论
  • php网站集成支付宝接口下载免费网络软件
  • 卡盟网站是怎么建设的用花生壳做网站速度可以吗
  • 杭州物联网前十名公司优秀seo平台
  • 网新中英企业网站管理系统wordpress 登录 缓存
  • wordpress模板建站教程wordpress添加广告位手机自适应
  • h5游戏平台入口优化是什么梗
  • 建设银行对公网站打不开网络推广活动方案主题和思路
  • 茶叶网站开发目的和意义网页设计需要考什么证
  • 高端企业网站建设公司怎么做实用性建设网站都需要哪些
  • 网站备案必须要幕布吗易企秀网站怎么做轮播图
  • 南昌网站排名优化四线城市网站建设方向及营利点
  • 做网站需要钱吗unity 做网站