当前位置:首页 » 《随便一记》 » 正文

深入浅出Pytorch函数——torch.ones

8 人参与  2023年05月08日 18:49  分类 : 《随便一记》  评论

点击全文阅读


分类目录:《深入浅出Pytorch函数》总目录
相关文章:
· 深入浅出Pytorch函数——torch.Tensor
· 深入浅出Pytorch函数——torch.ones
· 深入浅出Pytorch函数——torch.zeros
· 深入浅出Pytorch函数——torch.full
· 深入浅出Pytorch函数——torch.ones_like
· 深入浅出Pytorch函数——torch.zeros_like
· 深入浅出Pytorch函数——torch.full_like


语法

torch.ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor

参数

size:大小,定义输出张量形状的整数序列。可以是可变数量的参数或集合,如:列表或元组。out:[可选,Tensor] 输出张量dtype:[可选,torch.dtype] 返回张量的所需数据类型。如果为None,则使用全局默认值(参考torch.set_default_tensor_type())。layout:[可选,torch.layout] 返回张量的期望内存布局形式,默认为torch.strideddevice:返回张量的期望计算设备。如果为None,使用当前的设备(参考torch.set_default_tensor_type()),设备将CPU用于CPU张量类型,将CUDA设备用于CUDA张量类型。requires_grad:[可选,bool] 是否需要自动微分,默认为False

返回值

返回一个每个元素都是1、形状为size、数据类型为dtype的Tensor。

实例

>>> torch.ones(2, 3)tensor([[ 1.,  1.,  1.],        [ 1.,  1.,  1.]])>>> torch.ones(5)tensor([ 1.,  1.,  1.,  1.,  1.])

点击全文阅读


本文链接:http://zhangshiyu.com/post/61637.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1