Skip to content

Instantly share code, notes, and snippets.

@darden1
Created April 11, 2018 10:37
Show Gist options
  • Select an option

  • Save darden1/78e5aa82ed0839b29299977d8cec258e to your computer and use it in GitHub Desktop.

Select an option

Save darden1/78e5aa82ed0839b29299977d8cec258e to your computer and use it in GitHub Desktop.
onehot_matrix_check.py
import numpy as np
n = 3
m = 3
B = np.random.rand(n,m)
Y = np.zeros_like(B)
for i in range(Y.shape[0]):
Y[i, np.random.choice(np.arange(Y.shape[1]), 1)] = 1
dLdB = Y/B
print("-"*40)
print("B:")
print(B)
print("-"*40)
print("Y:")
print(Y)
print("-"*40)
print("dLdB:")
print(dLdB)
print("-"*40)
print("np.dot(dLdB, B.T):")
print(np.dot(dLdB, B.T))
print("-"*40)
print("np.diag(np.dot(dLdB, B.T)):")
print(np.diag(np.dot(dLdB, B.T)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment