Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

labels = (np.arange(num_labels) == labels[:,None]).astype(np.float32) error boolean #7

Open
aryopg opened this issue Oct 26, 2016 · 1 comment

Comments

@aryopg
Copy link

aryopg commented Oct 26, 2016

can you explain what does it mean?

@luisgc2116
Copy link

It is a way to one-hot-encode the labels. If you break it down, you take the number of labels through a numpy array as such:

Say you have two numpy arrays with the labels and target_vectors.
n_labels = 3
labels_np = np.arange(n_labels)
target_vector = np.array([2,1,0])

Now, target_vector[:,None] returns the array [[2],[0],[1]], which is a column vector. If we
labels_np == target_vector[:,None] return the following boolean array:
[[False False True]
[ True False False]
[False True False]]

Now, the last part, astype(np.float32) simply makes these boolean outputs into integers 0 or 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants