0Pricing
Deep Learning Academy · Aula

Seu Primeiro torch.tensor

Crie um tensor e mostre sua forma e seu tipo de dados

Seu Primeiro torch.tensor é uma aula grátis de Deep Learning Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Deep Learning Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Deep Learning Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Meet the Tensor

A tensor is PyTorch's core data container, a grid of numbers much like a NumPy array but ready to run on a GPU. 🧮

Create One from a List

The simplest way to make a tensor is torch.tensor from a Python list. PyTorch copies your numbers into a fast numerical grid.

x = torch.tensor([1, 2, 3])

Print It Out

Printing a tensor shows its values wrapped in tensor(...), so you always know you are looking at PyTorch data, not a plain list.

print(x)

Shape Describes Structure

The shape tells you the size along each dimension. A flat list of three values has a shape of three.

print(x.shape)

Build a 2D Tensor

Nest lists to make a grid. This matrix has two rows and three columns, so its shape reads as two by three.

m = torch.tensor([[1, 2, 3], [4, 5, 6]])

Dtype Is the Number Type

Every tensor has a dtype, the kind of number it stores. Whole numbers become int64, decimals become float32 by default.

print(x.dtype)

Floats for Training

Networks learn with decimals, so most model data is float32. Add a decimal point and PyTorch picks the float type for you.

y = torch.tensor([1.0, 2.0, 3.0])

Set the Dtype Yourself

You can request a type directly with the dtype argument, which is handy when you need floats from integer input.

z = torch.tensor([1, 2], dtype=torch.float32)

Tensors Full of Zeros

Need a blank tensor of a given size? torch.zeros fills the shape you ask for with zeros, perfect as a starting buffer.

torch.zeros(2, 3)

Random Tensors

Model weights often start random. torch.rand gives a tensor of the shape you choose, filled with values between zero and one.

torch.rand(2, 3)

Count the Dimensions

The number of dimensions is the tensor's rank. Read it with .ndim: a vector is rank one, a matrix is rank two.

print(m.ndim)

Quick Check

Reason about the shape of a nested-list tensor.

Recap

You created tensors from lists, read their shape and dtype, and made zeros and random grids. This is the data deep learning runs on. ✅

Perguntas Frequentes

A aula “Seu Primeiro torch.tensor” é grátis?

Sim — o texto completo de “Seu Primeiro torch.tensor” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Deep Learning Academy, atualize para CoddyKit PRO. O curso de Deep Learning Academy inclui 4 aulas no total.

O que vou aprender em “Seu Primeiro torch.tensor”?

Crie um tensor e mostre sua forma e seu tipo de dados Você pratica Deep Learning Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Deep Learning Academy?

Nenhuma experiência prévia é necessária. Deep Learning Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Seu Primeiro torch.tensor”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Deep Learning Academy?

Sim. Cada aula de Deep Learning Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Instale PyTorch e Verifique a Importação
  2. CPU vs GPU vs MPS: Escolha um Dispositivo
  3. Notebooks, Scripts e Sementes Reproduzíveis
  4. Seu Primeiro torch.tensor
← Voltar para Deep Learning Academy