Pythonのリストからndarrayへ
数値処理で配列がリストより優れている理由を学びます
「Pythonのリストからndarrayへ」はCoddyKit上の無料Data Science Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはData Science Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Data Science Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Meet the ndarray
NumPy's core gift is the ndarray, a grid of numbers all of one type. It is the workhorse behind almost every data tool you'll use. 🚀
Lists Are Flexible but Slow
A Python list can hold anything: numbers, strings, even other lists. That freedom is handy, but for crunching numbers it makes the list slow.
Arrays Are Fast and Strict
An array trades flexibility for speed. Every element shares one dtype, so NumPy stores them tightly and computes on them at near-C speed.
Your First Array
You build an array by passing a list to np.array. NumPy reads the values and wraps them into a fast numeric grid for you.
import numpy as np
arr = np.array([1, 2, 3, 4])One Type Rules Them All
Mix an int and a float in one array and NumPy quietly promotes everything to float, because all elements must share a single type.
np.array([1, 2, 3.5]) # becomes float64Why Speed Comes Free
Because the type is fixed, NumPy skips the per-item checks a list needs. This vectorization is why arrays fly through millions of numbers. ⚡
Arrays Live in One Block
List items scatter across memory, but an array sits in one contiguous block. Your CPU loves that, reading values in tight, predictable bursts.
Make Arrays From Scratch
You don't always start from a list. np.zeros and np.ones fill an array with a chosen value, perfect for placeholders you fill in later.
np.zeros(5) # array([0., 0., 0., 0., 0.])Ranges the NumPy Way
Need an even sequence? np.arange works like Python's range but hands you back an array ready for math.
np.arange(0, 10, 2) # 0 2 4 6 8Same Idea, Bigger Dimensions
An array isn't limited to one row. Pass nested lists and you get a 2D grid, the matrix shape that powers tables and images.
np.array([[1, 2], [3, 4]])The Foundation of Everything
pandas, scikit-learn, and matplotlib all sit on top of the ndarray. Master this one type and the whole data stack opens up. 🧱
Quick Check
Let's check the key difference between lists and arrays.
Recap
You met the ndarray: a single-type, tightly packed grid that beats lists for numbers. Build it with np.array, zeros, or arange, then let the speed work for you. 🎉
よくある質問
「Pythonのリストからndarrayへ」レッスンは無料ですか?
はい。「Pythonのリストからndarrayへ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Data Science Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Data Science Academyコースには全4レッスンが含まれています。
「Pythonのリストからndarrayへ」で何を学びますか?
数値処理で配列がリストより優れている理由を学びます ブラウザで直接実行するハンズオンコードでData Science Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Data Science Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのData Science Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「Pythonのリストからndarrayへ」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このData Science Academyレッスンでコードを書いて実行できますか?
はい。すべてのData Science Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Pythonのリストからndarrayへ
- Shape、Size、dtype
- ループなしのベクトル化数学
- 配列のインデックス指定とスライス