identity関数【numpy】
説明:単位行列からなる配列を生成する。
書式:
numpy.identity(【引数】)
引数:単位行列のサイズ、単位行列は正方行列なのでいずれかの軸向きの長さを指定する。
戻り値:正方行列が格納された配列のインスタンス。
code:identity1.py
import numpy as np
i1 = np.identity(1)
print('i1:\n', i1, i1.shape)
i2 = np.identity(3)
print('i2:\n', i2, i2.shape)
関連:shape属性【numpy】
https://scrapbox.io/files/6506689eb847b0001bb4a44e.png