pytorch笔记:tensor 基础

来自B站视频,官网教程,API查阅

文章目录

  • 创建 tensor
  • tensor 运算
  • tensor 操作
  • tensor 属性

创建 tensor

  • torch.tensor
  • torch.ones_like
  • torch.zeros_like
  • torch.rand_like
  • torch.rand

Returns a tensor filled with random numbers from a uniform distribution on the interval [0, 1)[0,1)

  • torch.randn

Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution).

  • torch.normal(mean,std,size)
  • torch.zeros
  • torch.arange

torch.range() is deprecated and will be removed in a future release because its behavior is inconsistent with Python’s range builtin. Instead, use torch.arange(), which produces values in [start, end).

  • torch.eye
  • torch.full([n,n],x)
    移动 tensor
if torch.cuda.is_available():
	tensor=tensor.to('cuda')

tensor 运算

  • torch.is_tensor
  • torch.numel,返回元素数目

tensor 操作

  • torch.cat

除了dim指定的那个维度,其他维度的shape都应该一样

  • torch.reshape(a,shape)

shape可以用 [] 或 () 指定

  • torch.split(a,size)

按size大小均分或者可以传入list

  • torch.squeeze
  • troch.tile(a,dims)

扩增a的行列

  • torch.transpose(a,dim0,dim1)
  • torch.unbind
  • torch.unsqueeze(a,dim)

tensor 属性

TENSOR ATTRIBUTES

你可能感兴趣的:(学习笔记,pytorch,笔记,python)