Hvass-Labs / TensorFlow-Tutorials

TensorFlow Tutorials with YouTube Videos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

np eye visualization.

Caspain opened this issue · comments

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.

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

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?

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.]])