Created
December 31, 2019 09:15
-
-
Save SuvroBaner/77d4fc3638ebd0e71df5f94d6464bb11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def one_hot_matrix(labels, Con): | |
""" | |
Creates a matrix where the i-th row corresponds to the ith class number and the jth column | |
corresponds to the jth training example. So if example j had a label i. Then entry (i,j) | |
will be 1. | |
""" | |
C = tf.constant(Con, name = 'C') | |
one_hot_matrix = tf.one_hot(indices = labels, depth = C, axis = 0) | |
with tf.Session() as sess: | |
one_hot = sess.run(one_hot_matrix) | |
sess.close() | |
return one_hot | |
labels = np.array([1, 2, 0, 1]) | |
one_hot = one_hot_matrix(labels, Con = 3) | |
print(one_hot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment