In [1]:
import numpy as np
In [2]:
# https://docs.scipy.org/doc/numpy/reference/generated/numpy.eye.html
In [3]:
e = np.eye(4)
print(type(e))
print(e)
print(e.dtype)
In [4]:
e = np.eye(4, M=3, k=1, dtype=np.int8)
print(e)
print(e.dtype)
In [5]:
# https://docs.scipy.org/doc/numpy/reference/generated/numpy.identity.html
In [6]:
i = np.identity(4)
print(i)
print(i.dtype)
In [7]:
i = np.identity(4, dtype=np.uint8)
print(i)
print(i.dtype)
In [8]:
a = [3, 0, 8, 1, 9]
a_one_hot = np.identity(10)[a]
print(a)
print(a_one_hot)
In [9]:
a = [2, 2, 0, 1, 0]
a_one_hot = np.identity(3)[a]
print(a)
print(a_one_hot)