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

这篇具有很好参考价值的文章主要介绍了深入浅出Pytorch函数——torch.zeros。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

分类目录:《深入浅出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.zeros(*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.strided
  • device:返回张量的期望计算设备。如果为None,使用当前的设备(参考torch.set_default_tensor_type()),设备将CPU用于CPU张量类型,将CUDA设备用于CUDA张量类型。
  • requires_grad:[可选,bool] 是否需要自动微分,默认为False
返回值

返回一个每个元素都是0、形状为size、数据类型为dtype的Tensor。文章来源地址https://www.toymoban.com/news/detail-466976.html

实例
>>> torch.zeros(2, 3)
tensor([[ 0.,  0.,  0.],
        [ 0.,  0.,  0.]])

>>> torch.zeros(5)
tensor([ 0.,  0.,  0.,  0.,  0.])

到了这里,关于深入浅出Pytorch函数——torch.zeros的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 深入浅出Pytorch函数——torch.max

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出Pytorch函数——torch.max · 深入浅出Pytorch函数——torch.maximum torch.max 有三种输入形式,根据其输入形式及参数的不同有下列三种返回形式: torch.max(input) :返回输入张量所有元素的最大值。 torch.max(input, dim, keep

    2024年02月15日
    浏览(32)
  • 深入浅出Pytorch函数——torch.exp

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出TensorFlow2函数——tf.exp · 深入浅出TensorFlow2函数——tf.math.exp · 深入浅出Pytorch函数——torch.exp · 深入浅出PaddlePaddle函数——paddle.exp 对输入 input 逐元素进行以自然数 e e e 为底指数运算。 语法 参数 input :[ Te

    2024年02月11日
    浏览(32)
  • 深入浅出Pytorch函数——torch.squeeze

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出Pytorch函数——torch.squeeze · 深入浅出Pytorch函数——torch.unsqueeze 将输入张量形状为1的维度去除并返回。比如输入向量的形状为 A × 1 × B × 1 × C × 1 × D Atimes1times Btimes1times Ctimes1times D A × 1 × B × 1 × C × 1 ×

    2024年02月16日
    浏览(34)
  • 深入浅出Pytorch函数——torch.sum

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出TensorFlow2函数——tf.reduce_sum · 深入浅出TensorFlow2函数——tf.math.reduce_sum · 深入浅出Pytorch函数——torch.sum · 深入浅出PaddlePaddle函数——paddle.sum 语法 参数 input :[ Tensor ] 输入的张量。 dim :[可选, int / tuple ] 求和

    2024年02月04日
    浏览(57)
  • 深入浅出Pytorch函数——torch.tensor

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出TensorFlow2函数——tf.constant · 深入浅出Pytorch函数——torch.tensor · 深入浅出Pytorch函数——torch.as_tensor · 深入浅出Pytorch函数——torch.Tensor · 深入浅出PaddlePaddle函数——paddle.to_tensor 基于 data 构建一个没有梯度历史

    2024年02月04日
    浏览(84)
  • 深入浅出Pytorch函数——torch.t

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出TensorFlow2函数——tf.transpose · 深入浅出Pytorch函数——torch.t · 深入浅出Pytorch函数——torch.transpose · 深入浅出PaddlePaddle函数——paddle.transpose 语法 参数 input : [Tensor] 输入的张量。 返回值 被转置的张量。 实例

    2024年02月11日
    浏览(36)
  • 深入浅出Pytorch函数——torch.ones

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

    2023年04月26日
    浏览(90)
  • 深入浅出Pytorch函数——torch.maximum

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出Pytorch函数——torch.max · 深入浅出Pytorch函数——torch.maximum 计算 input 和 other 的元素最大值。 语法 参数 input :[ Tensor ] 输入张量 other :[ Tensor ] 输入的第二个张量 实例

    2024年02月15日
    浏览(31)
  • 深入浅出PyTorch函数torch.rand与torch.randn

    torch.rand 和 torch.randn 都是PyTorch中用于生成随机张量的函数,但它们生成随机数的方式有所不同。 torch.rand 生成在区间 [0, 1) 内均匀分布的随机数。 size 参数是一个表示所需张量形状的元组或整数。可以生成任何形状的随机张量。 torch.randn 生成从标准正态分布(均值为0,标准

    2024年02月09日
    浏览(29)
  • 深入浅出Pytorch函数——torch.Tensor.backward

    分类目录:《深入浅出Pytorch函数》总目录 相关文章: · 深入浅出Pytorch函数——torch.Tensor 计算当前张量相对于图的梯度,该函数使用链式法则对图进行微分。如果张量不是一个标量(即其数据具有多个元素)并且需要梯度,则函数还需要指定梯度,指定的梯度应该是一个与

    2024年02月15日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包