2.7 文档(Pytorch)

  由于本书篇幅的限制,我们不可能介绍每一个单独的【PyTorch】函数和类。API文档,其他教程和示例提供了许多本书之外的文档。在本节中,我们将为您提供一些探索【PyTorch API】的指导。

2.7.1 查找模块中的所有函数和类

  为了知道模块中可以调用哪些函数和类,我们调用了【dir】函数。例如,我们可以查询模块中用于生成随机数的所有属性:

import torchprint(dir(torch.distributions))# 输出如下
['AbsTransform', 'AffineTransform', 'Bernoulli', 'Beta', 'Binomial', 'CatTransform', 'Categorical', 'Cauchy', 'Chi2', 'ComposeTransform', 'ContinuousBernoulli', 'CorrCholeskyTransform', 'Dirichlet', 'Distribution', 'ExpTransform', 'Exponential', 'ExponentialFamily', 'FisherSnedecor', 'Gamma', 'Geometric', 'Gumbel', 'HalfCauchy', 'HalfNormal', 'Independent', 'IndependentTransform', 'Kumaraswamy', 'LKJCholesky', 'Laplace', 'LogNormal', 'LogisticNormal', 'LowRankMultivariateNormal', 'LowerCholeskyTransform', 'MixtureSameFamily', 'Multinomial', 'MultivariateNormal', 'NegativeBinomial', 'Normal', 'OneHotCategorical', 'OneHotCategoricalStraightThrough', 'Pareto', 'Poisson', 'PowerTransform', 'RelaxedBernoulli', 'RelaxedOneHotCategorical', 'ReshapeTransform', 'SigmoidTransform', 'SoftmaxTransform', 'StackTransform', 'StickBreakingTransform', 'StudentT', 'TanhTransform', 'Transform', 'TransformedDistribution', 'Uniform', 'VonMises', 'Weibull', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'bernoulli', 'beta', 'biject_to', 'binomial', 'categorical', 'cauchy', 'chi2', 'constraint_registry', 'constraints', 'continuous_bernoulli', 'dirichlet', 'distribution', 'exp_family', 'exponential', 'fishersnedecor', 'gamma', 'geometric', 'gumbel', 'half_cauchy', 'half_normal', 'identity_transform', 'independent', 'kl', 'kl_divergence', 'kumaraswamy', 'laplace', 'lkj_cholesky', 'log_normal', 'logistic_normal', 'lowrank_multivariate_normal', 'mixture_same_family', 'multinomial', 'multivariate_normal', 'negative_binomial', 'normal', 'one_hot_categorical', 'pareto', 'poisson', 'register_kl', 'relaxed_bernoulli', 'relaxed_categorical', 'studentT', 'transform_to', 'transformed_distribution', 'transforms', 'uniform', 'utils', 'von_mises', 'weibull']

  通常,我们可以忽略以 “__” 开始和结束的函数(它们是Python中的特殊对象)或以单个 “_” 开始的函数(通常是内部函数)。根据剩下的函数或属性名,我们可以猜测这个模块提供了各种生成随机数的方法,包括从均匀分布(均匀)、正态分布(正态)和多项分布(多项)中抽样。

2.7.2 查找特定函数和类的用法

  关于如何使用给定函数或类的更具体的说明,我们可以调用【help】函数。作为一个例子,让我们探讨张量的函数【ones】的用法说明,具体代码如下:

# 特定函数的用法说明
help(torch.ones)# 输出如下
Help on built-in function ones:ones(...)ones(*size, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> TensorReturns a tensor filled with the scalar value `1`, with the shape definedby the variable argument :attr:`size`.Args:size (int...): a sequence of integers defining the shape of the output tensor.Can be a variable number of arguments or a collection like a list or tuple.Keyword arguments:out (Tensor, optional): the output tensor.dtype (:class:`torch.dtype`, optional): the desired data type of returned tensor.Default: if ``None``, uses a global default (see :func:`torch.set_default_tensor_type`).layout (:class:`torch.layout`, optional): the desired layout of returned Tensor.Default: ``torch.strided``.device (:class:`torch.device`, optional): the desired device of returned tensor.Default: if ``None``, uses the current device for the default tensor type(see :func:`torch.set_default_tensor_type`). :attr:`device` will be the CPUfor CPU tensor types and the current CUDA device for CUDA tensor types.requires_grad (bool, optional): If autograd should record operations on thereturned tensor. Default: ``False``.Example::>>> torch.ones(2, 3)tensor([[ 1.,  1.,  1.],[ 1.,  1.,  1.]])>>> torch.ones(5)tensor([ 1.,  1.,  1.,  1.,  1.])

  从文档中,我们可以看到函数【ones】创建了一个具有指定形状的新张量,并将所有元素的值设为1。只要可能,你应该运行一个快速测试来确认你的理解:

# 测试
print(torch.ones(4))# 输出如下
tensor([1., 1., 1., 1.])

动手学习深度学习——2.7 文档(Pytorch)相关推荐

  1. Keras深度学习实战(26)——文档向量详解

    Keras深度学习实战(26)--文档向量详解 0. 前言 1. 文档向量基本概念 2. 神经网络模型与数据集分析 2.1 模型分析 2.2 数据集介绍 3. 利用 Keras 构建神经网络模型生成文 ...

  2. 【动手撸深度学习】细粒辨花 一文实践清华博士Densenet

    hello ,大家好,欢迎来到动手撸深度学习,一个必看系列,我会将动手撸深度学习一直完善下去,让文章更精彩,更优秀,之所以选择付费,主要是文章原创,全是干货,大家可以看我的个人信息,点赞数,收藏数,可 ...

  3. 「动手学深度学习」在B站火到没谁,加这个免费实操平台,妥妥天花板!

    论 AI 圈活菩萨,非李沐老师莫属. 前有编写「动手学深度学习」,成就圈内入门经典,后又在B站免费讲斯坦福 AI 课,一则艰深硬核讲论文的视频播放量36万,不少课题组从导师到见习本科生都在追番. 如此 ...

  4. 资源 | 李沐等人开源中文书《动手学深度学习》预览版上线

    来源:机器之心 本文约2000字,建议阅读10分钟. 本文为大家介绍了一本交互式深度学习书籍. 近日,由 Aston Zhang.李沐等人所著图书<动手学深度学习>放出了在线预览版,以供读 ...

  5. 《动手学深度学习》PyTorch版本

    Dive-Into-Deep-Learning-PyTorch-PDF 简介   本项目对中文版<动手学深度学习>中的代码进行整理,并参考一些优秀的GitHub项目给出基于PyTorch的 ...

  6. PyTorch 《动手学深度学习》学习笔记(Dive-into-DL-Pytorch)

    参考文章1:PyTorch版<动手学深度学习>PDF 版开源了 参考文章2:https://download.csdn.net/download/Dontla/12371960 文章目录 ...

  7. 【深度学习】李沐《动手学深度学习》的PyTorch实现已完成

    这个项目是中文版<动手学深度学习>中的代码进行整理,用Pytorch实现,是目前全网最全的Pytorch版本. 项目作者:吴振宇博士 简介   Dive-Into-Deep-Learnin ...

  8. 李沐《动手学深度学习》新增PyTorch和TensorFlow实现,还有中文版

    李沐老师的<动手学深度学习>已经有Pytorch和TensorFlow的实现了,并且有了中文版. 网址:http://d2l.ai/ 简介 李沐老师的<动手学深度学习>自一年前 ...

  9. 送10本今年最火的《动手学深度学习》

    点击我爱计算机视觉标星,更快获取CVML新技术 52CV曾经多次介绍FlyAI机器学习竞赛平台,不少粉丝也曾在FlyAI拿到现金奖励. 本次52CV & FlyAI联合送书,CV君查找了两天, ...

  10. 《动手学深度学习》TF2.0 实现

    本项目将<动手学深度学习> 原书中MXNet代码实现改为TensorFlow2.0实现.经过我的导师咨询李沐老师,这个项目的实施已得到李沐老师的同意.原书作者:阿斯顿·张.李沐.扎卡里 C ...

最新文章

  1. 运行js_最新双十一喵币自动领取方法,安卓手机通过js脚本完美运行
  2. 解密联想20年的45条法则
  3. DevExpress的TreeList实现显示本地文件目录并自定义右键实现删除与重命名文件
  4. python中case的用法_python中Switch/Case实现的示例代码
  5. oracle日常函数应用,oracle日常 常用函数与脚本
  6. django框架中的模型
  7. 【BZOJ2084】【洛谷P3501】[POI2010]ANT-Antisymmetry(Manache算法)
  8. ToB产品设计:用户权限系统解析
  9. STM32工作笔记0088---时间标志组和同时等待多个内核对象
  10. android 文件大小排序,android 文件列表排序
  11. python小程序100题-python 练习题:流量套餐订购小程序
  12. 跑马灯效果 例子 写法 利用闭包
  13. php 函数传值_传址_函数参数,php函数的传值与传址
  14. zTree中设置idKey跟pId对象关联
  15. 域名型通配符ssl证书_通配符SSL证书是否支持三级子域名?
  16. 小米9开发版自带root吗_小米9root权限获取教程
  17. 自考-计算机程序设计-1-概论
  18. 程序是虚幻的,点心是真实的20050425
  19. python ppt 图片_python ppt 转 pdf 图片
  20. go 语言之“查找一个字符串中汉字个数”

热门文章

  1. 武职计算机网络技术专业,武汉职业技术学院计算机系
  2. 【视觉-单目三维重建-理论篇】单目视觉三维重建----论文调研1
  3. Java框架学习笔记--Mybatis学习
  4. 需求分析岗的一般工作流程
  5. 基于Java的地理位置定位系统
  6. 手机使用电脑自带功能进行投屏
  7. 如何在 JIRA 中创建自己的仪表板(Dashboard)
  8. Gradle的概念和理解.
  9. 计算机系大神和数学系系花,小甜文:《一贱钟情,大神求放过》1v1双C,男主小奶狗,全程高甜...
  10. 手动制作满足SARscape要求的_dem数据