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

比特币网站建设网站使用网络图片做素材 侵权

比特币网站建设,网站使用网络图片做素材 侵权,wordpress文章选项,网站定制开发流程和功能由于我只简单的学过python和pytorch,其中有很多函数的操作都还是一知半解的,其中有些函数经常见到,所以就打算记录下来。 1.zip zip(*a):针对单个可迭代对象压缩成n个元组,元组数量n等于min(a中元素的最小长度) a [(1, 2), (3…

由于我只简单的学过python和pytorch,其中有很多函数的操作都还是一知半解的,其中有些函数经常见到,所以就打算记录下来。

1.zip

zip(*a):针对单个可迭代对象压缩成n个元组,元组数量n等于min(a中元素的最小长度)

a = [(1, 2), (3, 4), (5, 6)]
c, d = zip(*a)
print(c, d)
# (1, 3, 5) (2, 4, 6)

2.view, arange和range

import torch
# torch.arange(1, 3) =[1,3)   前闭后开
# torch.range(1, 3) =[1,3]    前闭后闭
e = torch.arange(1, 3)
e1 = torch.range(1, 3)
e, e1  # (tensor([1, 2]), tensor([1., 2., 3.]))

view的作用就是用来组织Tensor的形状,

import torch
e = torch.arange(1, 19).view(2, 3, 3)
e1 = torch.range(1, 18).view(2, 3, 3)
e,e1,e==e1

输出结果如下
在这里插入图片描述

3.torch.transpose 用来交换维度(重新组织维度)

torch.Size([1, 3, 2])–>transpose(0,1)后 torch.Size变为([3,1,2])
有两种写法 ① b.transpose(0, 1) ② torch.transpose(b, 0, 1),我觉得都可以使用

import torch
#https://pytorch.org/docs/stable/generated/torch.transpose.html#torch.transpose
b = torch.Tensor([[[0, 1], [2, 3], [4, 5]]])
print(b.shape)
print('----------')
b=b.transpose(0, 1)
print(b.shape)
print('----------')
c = torch.transpose(b, 0, 1)
print(c.shape)
# print(b)
# print(c)

在这里插入图片描述

4.torch.cat

torch.cat()是为了把多个tensor进行拼接而存在的(这里仅仅用了相同的元素)

# 3.torch.cat
# dim(整数,可选)– 张量被控制的维度
# m 默认为0  代表在竖向的方向上添加
# [c,
#  c,
#  c]
# m为1代表在横向的方向上添加[c,c,c]
c = torch.Tensor([[0, 1], [2, 3], [4, 5]])
# print(c)
print(c.shape)
print('--------------')
c1 = torch.cat((c, c, c), dim=0)  
# print(c1)
print(c1.shape)
print('--------------')
c2 = torch.cat((c, c), dim=1)  #  [c,c]
# print(c2)
print(c2.shape)
# print(c2.shape[1])

5.数组操作

这部分的操作比较复杂,有的三维数组的操作,就像这样的[:::],大家可以自己复制尝试一下,查看输出

# 4.数组操作
#  enc_hidden[-2,:,:], enc_hidden[-1,:,:]
d = torch.Tensor([[[1, 2, 3], [4, 5, 6], [7, 8, 9]],[[10, 11, 12], [13, 14, 15], [16, 17, 18]]])
print(d.size())  # torch.Size([2, 3, 3])
print(d)
# tensor([[[ 1.,  2.,  3.],
#          [ 4.,  5.,  6.],
#          [ 7.,  8.,  9.]],
#
#         [[10., 11., 12.],
#          [13., 14., 15.],
#          [16., 17., 18.]]])
print('------1---------')
print(d[-1, :, :])print('------2--------')
print(d[:, -1, :])print('------3--------')
print(d[:, :, -1])print('------4--------')
print(d[:, :, -2])print('------5--------')
print(d[-1])
print(d[:, :, -1])
print(d[-1, :, :])
print(d[:, -1, :])

6.squeeze()和unsqueeze()

squeeze在的中文意思压缩,unsqueeze取消压缩,unsqueeze是添加维度的意思

特别的,当unsqueeze()里面参数是0 的时候,该矩阵由(3,4)变成是(3,4,1)

e = torch.arange(1, 19).view(2, 3, 3)
print(e)
print(e.shape)
print('-----unsqueeze:就是在某个位置增加一个维度-------')
ee = e.unsqueeze(3)
print(ee)
print(ee.shape)

在这里插入图片描述在这里插入图片描述

# 5.squeeze()和unsqueeze()
#   squeeze在的中文意思压缩,就是降低维度,squeeze()函数只能压缩维度为1的矩阵
#  当unsqueeze()里面参数是0 的时候,该矩阵由(3,4)变成是(3,4,1)
# 对形如(2, 3, 3)的矩阵squeeze不起作用,但不会报错
e = torch.arange(1, 19).view(2, 3, 3)
print(e)
print(e.shape)
print('-----squeeze:就是在某个位置降低一个维度-------')
eee = e.squeeze(0)
print(eee)
print(eee.shape)

在这里插入图片描述

7.torch.bmm 计算两个tensor的矩阵乘法

torch.bmm(input, mat2, *, out=None)
input and mat2 must be 3-D tensors each containing the same number of matrices.

If input is a (b×n×m) tensor, mat2 is a (b×m×p) tensor, out will be a (b×n×p) tensor.

两个tensor的第一维是相等的,然后第一个数组的第三维和第二个数组的第二维度要求一样,对于剩下的则不做要求,输出维度

import torchg1 = torch.arange(1, 7).view(1, 2, 3)
print(g1.shape)
print(g1)
g2 = torch.arange(1, 10).view(1, 3, 3)
print(g2)
print('-------')torch.bmm(g1, g2)

在这里插入图片描述

8.torch.exp(x) 计算e(2.7)的x次方

分别计算e^0(e的0次方), e的1次方,e的log(2)次方

import matha = torch.tensor([0, 1, math.log(2)])
print(torch.exp(a))

在这里插入图片描述

9.torch.max

求最大值

a = torch.randn(4, 4)
print(a)
print(torch.max(a, dim=1))
print('----------')
print(torch.max(a, dim=1, keepdim=True))

在这里插入图片描述

http://www.yayakq.cn/news/697649/

相关文章:

  • 桂林设计单位资质升级网站在百度上怎么注册网站
  • jsp网站开发四酷全书贵阳网站建设搜王道下拉
  • 网站开发与维护是做什么工作电脑上常用的办公软件
  • 国外网站做问卷重庆公司社保缴费比例
  • 网页制作3个网页的网站图片仿站小工具+wordpress
  • 网页制作软件安卓版yoast wordpress seo 设置教程
  • 广州网站开发广州亦客网络解答怎么做网站广告位
  • 卖狗做网站什么关键词最好wap歌词
  • 做网站的数据从哪里来网站仿
  • 站内关键词排名优化软件网络广告营销的典型案例
  • 免费招聘网站招聘ios软件开发前景
  • 怎么做汽车网站推广方案开店做网站有什么好处
  • 竞价网站策划打开建设银行官方网站首页
  • 有没有网站做lol网站的网站的设计与应用论文
  • php 显示不同网站内容建设部网站政策法规
  • 杭州画廊网站建设公司名字大全3个字
  • 无锡网站建设报价wordpress 猫
  • 如何判断网站是否被k三网合一网站远吗
  • 怎么做 在线电影网站seo网络营销推广公司
  • 广州seo网站推广平台虚拟产品网站
  • 美术馆网站建设方案html网站尾部怎么做
  • 网站做关键词贵州有网站的企业
  • 中交建设集团网站分公司北京新增死亡病例详情
  • 中小企业网站制作塞尼铁克wordpress gstatic
  • 网站空间的后台控制面板学编程课对孩子有什么好处
  • 网站开发的客户群体中国宁波网站
  • 网站三要素关键词 描述怎么做网站宣传的方法主要有
  • 网站建设收费流程小企业财务软件免费版
  • 网站制作软件排行榜aso优化违法吗
  • 响应式网站公司做网站需要自备服务器吗