主要内容源于对PyTorch的doc的阅读: Doc
Tensor的element-wise的乘法是直接使用 * 。而Tensor之间的矩阵乘法使用Tensor.mm()方法。
仅记录了我认为比较常用和有用的API。
torch.is_tensor(obj),若obj为Tensor类型,那么返回True。
torch.numel(obj),返回Tensor对象中的元素总数。
torch.eye(n),返回一个单位方阵,和MATLAB的eye()非常像。还有其他参数。
torch.from_numpy(obj),利用一个numpy的array创建Tensor。注意,若obj原来是1列或者1行,无论obj是否为2维,所生成的Tensor都是一阶的,若需要2阶的Tensor,需要利用view()函数进行转换。
torch.linspace(start, end, steps),返回一个1维的Tensor。
torch.ones(),与MATLAB的ones很接近。
torch.ones_like(input),返回一个全1的Tensor,其维度与input相一致。
torch.arange(start, end, step),直接返回一个Tensor而不是一个迭代器。
torch.zeros(),与MATLAB的zeros很像。
torch.zeros_like(),与torch.ones_like()类似。
torch.cat(seq, dim),将tuple seq中描述的Tensor进行连接,通过实例说明用法。
torch.chunk(input, chunks, dim),与torch.cat()的作用相反。注意,返回值的数量会随chunks的值而发生变化.
torch.index_select(input, di