0Pricing
Data Science Academy · レッスン

Shape、Size、dtype

配列の構造を読み解きます

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

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

Read the Array's Anatomy

Every array carries metadata about itself. Three labels tell you almost everything: its shape, its size, and its dtype. Let's read each one. 🔍

Shape: Rows and Columns

The shape is a tuple of dimension lengths. A 3-by-4 grid reports (3, 4): three rows down, four columns across.

a = np.zeros((3, 4))
a.shape  # (3, 4)

Shape Tells You the Layout

Shape is your first sanity check. If a model expects (100, 5) and you hand it (5, 100), the shape mismatch is where bugs hide.

ndim: How Many Dimensions

The ndim attribute counts dimensions. A flat row is 1, a table is 2, a stack of tables is 3. It is just the length of the shape.

a.ndim  # 2

Size: Total Element Count

The size is the total number of elements, the product of every shape value. A (3, 4) array has a size of 12.

a.size  # 12

dtype: The One Shared Type

The dtype names the single type all elements share, like int64 or float64. It controls both precision and memory use.

np.array([1, 2, 3]).dtype  # int64

Choose Your dtype on Purpose

You can set the type yourself with the dtype argument. Use a smaller type like int32 to save memory on huge arrays.

np.array([1, 2, 3], dtype='int32')

dtype Affects Precision

float32 holds fewer decimals than float64. Tiny rounding gaps add up, so pick the type your numbers actually need.

Convert With astype

Already have an array? astype returns a copy in a new type, handy for turning floats into clean integers.

f = np.array([1.0, 2.0])
f.astype('int64')

itemsize: Bytes Per Element

The itemsize tells you bytes per element. Multiply it by size to estimate the array's total memory footprint.

a.itemsize  # 8 for float64

Inspect Before You Compute

Checking shape and dtype first saves hours. They reveal mismatched data and wrong types before a calculation quietly goes wrong. ✅

Quick Check

Let's test your read of an array's shape.

Recap

You can now read an array at a glance: shape for layout, ndim and size for counts, and dtype for the shared type. These four checks catch most bugs early. 🎉

よくある質問

「Shape、Size、dtype」レッスンは無料ですか?

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

「Shape、Size、dtype」で何を学びますか?

配列の構造を読み解きます ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

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

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

「Shape、Size、dtype」レッスンにはどのくらい時間がかかりますか?

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

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

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

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

  1. Pythonのリストからndarrayへ
  2. Shape、Size、dtype
  3. ループなしのベクトル化数学
  4. 配列のインデックス指定とスライス
← Data Science Academyに戻る