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

np eye visualization. #23

Closed
Caspain opened this issue Mar 6, 2017 · 3 comments
Closed

np eye visualization. #23

Caspain opened this issue Mar 6, 2017 · 3 comments

Comments

@Caspain
Copy link

Caspain commented Mar 6, 2017

result = np.eye(num_classes, dtype=float)
print(result)
ans = result[class_numbers]

i do not understand the array qualifier on the result for no.eye(). for lesson 9, you had over 4170 class_numbers as a list.

np.eye(3) returns
array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]])
so how array([[1, 0, 0],
[0, 1, 0],
[0, 0, 1]]) [4170] works?

i am seriously confused.

@Hvass-Labs
Copy link
Owner

Hvass-Labs commented Mar 6, 2017

I'm sorry but I don't understand your question and I cannot find this code in Tutorial 09.

@Caspain
Copy link
Author

Caspain commented Mar 6, 2017

well it was lesson 9(video data) it was the one_hot_encoded method return statement.
return np.eye(num_classes)[class_numbers]. Could you explain whats going on here?

@Hvass-Labs
Copy link
Owner

It is a fast way of converting class-numbers to one-hot encoded arrays. I think one-hot encoded arrays were explained in one of the early tutorials.

Here's an example:

Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:53:06) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.eye(10)
array([[ 1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.]])
>>> a = np.eye(10)
>>> a[3]
array([ 0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.])
>>> a[5]
array([ 0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.])
>>> a[[3,5]]
array([[ 0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.,  1.,  0.,  0.,  0.,  0.]])

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