Skip to Content
Pythonデータサイエンスハンドブック 第2版 ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習
book

Pythonデータサイエンスハンドブック 第2版 ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

by Jake VanderPlas, 菊池 彰
February 2024
Intermediate to advanced
576 pages
9h 17m
Japanese
O'Reilly Japan, Inc.
Content preview from Pythonデータサイエンスハンドブック 第2版 ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

7章集約:最大、最小、その他データの性質を表すもの

データに対峙した際、最初に行うのはデータの要約統計量の計算です。おそらく、最も一般的な要約統計量は平均値と標準偏差です。これらはデータセットの「典型的な」値の知識を与えてくれますが、その他の集計値も同様に有用です(合計、積、中央値、最小値、最大値、分位数など)。

NumPyは、配列の集計値を高速に計算する組み込み関数を提供しています。ここでは、その使用例をいくつか示します。

7.1 配列の合計

簡単な例として、配列内の全要素を合計します。Pythonの組み込みsum関数で計算できます。

In [1]: import numpy as np
        rng = np.random.default_rng()

In [2]: L = rng.random(100)
        sum(L)
Out[2]: 52.76825337322368

NumPyのsum関数も同じ構文で使えます。単純なケースでは、値も同じになります。

In [3]: np.sum(L)
Out[3]: 52.76825337322366

しかし、コンパイルされたコードで行われるため、NumPyの演算はずっと高速です。

In [4]: big_array = rng.random(1000000) %timeit sum(big_array) %timeit np.sum(big_array) Out[4]: 89.9 ms ± 233 μs per loop (mean ± std. dev. of 7 runs, 10 loops each) 521 μs ± 8.37 μs per loop (mean ± std. dev. of 7 runs, 1000 loops ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pythonデータサイエンスハンドブック ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

Pythonデータサイエンスハンドブック ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

Jake VanderPlas, 菊池 彰
推薦システム実践入門 ―仕事で使える導入ガイド

推薦システム実践入門 ―仕事で使える導入ガイド

風間 正弘, 飯塚 洸二郎, 松村 優也
プロダクトマネージャーのしごと 第2版 ―1日目から使える実践ガイド

プロダクトマネージャーのしごと 第2版 ―1日目から使える実践ガイド

Matt LeMay, 永瀬 美穂, 吉羽 龍太郎, 原田 騎郎, 高橋 一貴

Publisher Resources

ISBN: 9784814400638Publisher Website