[python]numpyのnp.array()入門

カテゴリ: python

プログラム

import numpy as np


def showNpArray(ary):
    x = np.array(ary)

    print(x)         # オブジェクトのダンプ
    print(x.shape)   # 各次元のサイズ
    print(x.ndim)    # 何次元の配列か

showNpArray([1, 2, 3])

showNpArray([[1, 2, 3], [2, 4, 6]])

showNpArray([[1, 2, 3], [2, 4, 6], [3, 6, 9]])

実行結果

# showNpArray([1, 2, 3])
[1 2 3]
(3,)
1

# showNpArray([[1, 2, 3], [2, 4, 6]])
[[1 2 3]
 [2 4 6]]
(2, 3)
2

# showNpArray([[1, 2, 3], [2, 4, 6], [3, 6, 9]])
[[1 2 3]
 [2 4 6]
 [3 6 9]]
(3, 3)
2

Amazonでおトクに買い物する方法
AmazonチャージでポイントGET


Amazonは買いもの前にAmazonギフト券をチャージしてポイントをゲットしないと損!

こちらもおススメ

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です