0Pricing
Deep Learning Academy · レッスン

はじめてのtorch.tensor

テンソルを作成し、shapeとdtypeを表示します

「はじめてのtorch.tensor」はCoddyKit上の無料Deep Learning Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDeep Learning Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Deep Learning Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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. ✅

よくある質問

「はじめてのtorch.tensor」レッスンは無料ですか?

はい。「はじめてのtorch.tensor」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Deep Learning Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Deep Learning Academyコースには全4レッスンが含まれています。

「はじめてのtorch.tensor」で何を学びますか?

テンソルを作成し、shapeとdtypeを表示します ブラウザで直接実行するハンズオンコードでDeep Learning Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Deep Learning Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのDeep Learning Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「はじめてのtorch.tensor」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このDeep Learning Academyレッスンでコードを書いて実行できますか?

はい。すべてのDeep Learning Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. PyTorchをインストールしてインポートを確認する
  2. CPUとGPUとMPS:デバイスを選ぶ
  3. ノートブック、スクリプト、再現可能な乱数シード
  4. はじめてのtorch.tensor
← Deep Learning Academyに戻る