3,761 views
この記事は最終更新から 2289日 が経過しています。
a[ 4 ][ 3 ][ 2 ] の 3次元配列を作成し、この配列のいろいろな情報を取得してみる。
>>> import numpy as np
>>> a = np.floor(np.random.rand(4,3,2)*10)
>>> a
array([[[ 6., 6.],
[ 2., 5.],
[ 4., 4.]],
[[ 9., 4.],
[ 8., 7.],
[ 1., 9.]],
[[ 3., 0.],
[ 5., 9.],
[ 3., 8.]],
[[ 4., 4.],
[ 4., 6.],
[ 8., 8.]]])
(1) 次数
>>> a.ndim 3 >>> a[0].ndim 2 >>> a[0][0].ndim 1
(2) 各次元の要素数
>>> a.shape (4, 3, 2) >>> a[0].shape (3, 2) >>> a[0][0].shape (2,)
(3) 配列の要素数
>>> a.size 24 >>> a[0].size 6 >>> a[0][0].size 2
アクセス数(直近7日): ※試験運用中、BOT除外簡易実装済2026-01-24: 0回 2026-01-23: 0回 2026-01-22: 0回 2026-01-21: 2回 2026-01-20: 0回 2026-01-19: 0回 2026-01-18: 0回