day23 Tensor 操作5 入门 一起学 PyTorch吧,PyTorch从入门开始 每天都更新 超详细 参数 常用方法 简单案列 共同学习,共同进步 坚持

select(dim, index) –>Tensor or number 按照 index 中选定的维度将 tensor 切片。如果tensor 是一维的,则返回一个数字。否则,返回给定维度已经被移除的 tensor
参数:
        -- dim (int)- 切片的维度
        --index (int)- 用来选取的索引
注意:select() 等效于切片。例如, tensor.select(0, index) 等效于 tensor[index],tensor.select(2, index) 等效于 tensor[:, :, index].
set(source=None, storage_offset=0, size=None, stride=None) 设置底层内存,大小和步长。如果 tensor 是一个 tensor,则将会与本 tensor 共享底层内存并且有相同的大小和步长。改变一个 tensor 中的元素将会反映在另一个 tensor。如果 source 是一个 Storage,则将设置底层内存,偏移量,大小和步长。
参数:
        -- source (Tensor or Storage)- 用到的 tensor 或内存
        --storage_offset (int)- 内存的偏移量
        --size (torch.Size)- 需要的大小,默认为源 tensor 的大小。
        --stride(tuple)- 需要的步长,默认为 C 连续的步长。
share_memory_() 将底层内存移到共享内存中。如果底层内存已经在共享内存中是将不进行任何操作。在共享内存中的 tensor 不能调整大小。
例子:
>>> torch.Tensor(3, 4, 5).size()
torch.Size([3, 4, 5])
sort(dim=None, descending=False) -> (Tensor, LongTensor)
storage() –>torch.Storage 返回底层内存。
storage_offset() –>int 以储存元素的个数的形式返回 tensor 在内存中的偏移量。
例子:
>>> x = torch.Tensor([1, 2, 3, 4, 5])
>>> x.storage_offset()
0
>>> x[3:].storage_offset()
3
classmethod() storage_type()
type(new_type=None, async=False) 将对象投为指定的类型。如果已经是正确的类型, 则不会进行复制并返回原对象。
参数:
        -- new_type (type or string)- 需要的类型
        -- async (bool)- 如果为 True,并且源地址在固定内存中,目的地址在 GPU 或者相反,则会相对于源主异步执行复制。否则,该参数不发挥作用。
type_as(tesnor) tensor 投射为参数给定 tensor 类型并返回。如果 tensor 已经是正 确的类型则不会执行操作。等效于:self.type(tensor.type()) 参数: tensor (Tensor): 有所需要类型的 tensor
unfold(dim, size, step) –>Tensor 返回一个 tensor ,其中含有在 dim tianchong 度上所有大小为 size 的分片。两个分片之间的步长为 step。如果 _sizedim_ dim 维度的原始大小,则在返回 tensor 中的维度 dim 大小是 _(sizedim-size)/step+1_ 维度大小的附加维度将附加在返回的 tensor 中。
参数:
        -- dim (int)- 需要展开的维度
        -- size (int)- 每一个分片需要展开的大小
        --step (int)- 相邻分片之间的步长
例子:
>>> x = torch.arange(1, 8)
>>> x
1
2
3
4
5
6
7
[torch.FloatTensor of size 7]
>>> x.unfold(0, 2, 1) 
1 2 
2 3 
3 4 
4 5 
5 6 
6 7 
[torch.FloatTensor of size 6x2]
>>> x.unfold(0, 2, 2) 
1 2 
3 4 
5 6 
[torch.FloatTensor of size 3x2]
view(*args) –>Tensor 返回一个有相同数据但大小不同的 tensor。返回的 tensor 必须 有与原 tensor 相同的数据和相同数目的元素,但可以有不同的大小。一个 tensor 必须是连续的 contiguous() 才能被查看。
例子:
>>> x = torch.randn(4, 4)
>>> x.size()
torch.Size([4, 4])
>>> y = x.view(16)
>>> y.size()
torch.Size([16])
>>> z = x.view(-1, 8) # the size -1 is inferred from other
dimensions , →
>>> z.size()
torch.Size([2, 8])
view_as(tensor)
返回被视作与给定的 tensor 相同大小的原 tensor。等效于: self.view(tensor.size())  zero_() 0 填充该 tensor
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值