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

怎么免费建设自己网站重庆网站推广专家

怎么免费建设自己网站,重庆网站推广专家,wordpress 添加下载页面,南京公司网站建设平台本次将介绍一下 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.hkea.cn/news/14372572/

相关文章:

  • 网站后端开发流程奢侈品网站策划方案
  • 高端网站设计建设中山学校的网站建设
  • 厦门市做网站优化福建省 园区网互联及网站建设 网络部分题目
  • 浙江省建设厅继续教育官方网站微信里面的小程序怎么设置
  • 安徽建站之星网络营销服务工具
  • 查建筑企业信息的网站重庆seo公司怎么样
  • 网站建设项目建议书济南网络营销策划公司
  • 买域名做网站跳转工程施工公司
  • 免费浏览的网站产品设计考研学校排名
  • 网站建设所需要软件大庆公司做网站
  • 志愿海南网站哈佛门户网站建设特点
  • 郑州网站排名优化公司邢台市政
  • 沂源网站国内有名室内设计公司
  • 手机点了钓鱼网站怎么办网站开发相关书籍资料
  • 各种网站建设报价应用商店下载app
  • 腾讯云如何做网站兼职网站平台有哪些
  • 海口h5建站番禺制作网站系统
  • 织梦可以做论坛网站深圳建设集团有限公司有分公司吗
  • php yaf 网站开发框架模板网站怎么优化
  • 自己创造网站平台成都哪家公司做网站比较好
  • 智联招聘网站建设wordpress qq头像
  • 百度给公司做网站效果咋样凤凰军事网新闻最新消息
  • 绵阳市建设局官方网站佛山网站建设公司价格多少
  • 网站建设和关键词优化技巧建设一个门户网站
  • 上海网站建设润滋口碑好的邯郸网站建设
  • 电商网站设计流程做机械的专业外贸网站有哪些
  • 中小企业建网站注意安徽合肥制作网站公司吗
  • 求好的设计网站电商类网站开发
  • 网站平台建设合作协议wordpress appcan-wp
  • 注册公司代理记账网络seo是什么工作