一、简介
Tensor,又名张量,是pytorch、tensorflow、Theano等深度学习框架中重要的数据结构。关于张量的本质,我们可以简单的认为就是一个数组,它可以是一个数(标量)、一维数组(向量)、二维数组(矩阵)、多维数组…,pytorch的tensor支持GPU加速。
二、查看帮助文档
在ipython或者notebook中,使用function?方法或者help(function)方法可以查看一个函数的帮助文档,比如构造参数等等,以torch的save方法为例:
(1)function?方法
输入torch.save?
,shift+enter即可得到它的帮助文档
Docstring:
ones(*size, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) -> Tensor
Returns a tensor filled with the scalar value `1`, with the shape defined
by 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.
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 CPU
for CPU tensor types and the current CUDA device for CUDA tensor types.
requires_grad (bool, optional): If autograd should record operations on the
returned tensor. Default: ``False``.
Example::
>>> torch.ones(2, 3)
tensor([[ 1., 1., 1.],
[ 1., 1., 1.]])
>>> torch.ones(5)
tensor([ 1., 1., 1., 1., 1.])
Type: builtin_function_or_method
(2)help(function)方法
help(torch.save)
,enter+shift也可得到其帮助文档
需要注意的是,在使用上述两种方法的时候,一定要加上模块名,比如torch.save
,若只输入save?或help(save)则会提示NameError: name 'save' is not defined
。
三、
来源:CSDN
作者:东大艾弗森
链接:https://blog.csdn.net/weixin_45021364/article/details/104637474