In [1]:
import numpy as np
In [10]:
x = np.array([0,0,0,0,0,0,0,0,0])
In [11]:
x
Out[11]:
In [14]:
idx = np.random.choice(x,5,replace = False)
In [16]:
idx
Out[16]:
In [17]:
np.arange(len(x))
Out[17]:
In [20]:
t = np.random.choice(np.arange(len(x)),5,replace = True)
In [21]:
t
Out[21]:
In [22]:
x[t]
Out[22]:
In [23]:
x = np.array([[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]])
In [24]:
x
Out[24]:
In [25]:
t = np.random.choice(np.arange(len(x)),5,replace = True)
In [26]:
t
Out[26]:
In [27]:
x[t,:]
Out[27]:
In [31]:
x[0,2] = 5
In [33]:
np.argmax(x,axis=0)
Out[33]:
In [34]:
x
Out[34]:
In [1]:
import numpy as np
In [36]:
x = np.array([1,2,3,4,5,6])
In [37]:
np.exp(x)
Out[37]:
In [2]:
x = np.rand((5,5))
In [6]:
np.random.randn(5,5)
Out[6]:
In [9]:
X = np.random.randn(500,3073)
In [8]:
y = np.random.randn(500,1)
In [13]:
W = W = np.random.randn(3073, 10)
In [15]:
scores = X[1,:].dot(W)
In [18]:
scores = np.exp(scores)
# normalize
scores_sum = np.sum(scores)
scores = scores / scores_sum
In [19]:
scores.shape
Out[19]:
In [27]:
scores[2] #2=y[i]
Out[27]:
In [29]:
np.exp
Out[29]:
In [30]:
exp()
In [32]:
np.log(2)
Out[32]:
In [34]:
range(0,5) ==
Out[34]:
In [35]:
np.zeros(5)
Out[35]:
In [38]:
(3==3)*1
Out[38]:
In [52]:
X = np.array([[0,1,2,3],[0,1,2,3],[0,1,2,3]])
In [55]:
scores = (X.T - np.max(X,axis=1)).T
In [48]:
scores = np.exp(scores)
In [57]:
sum_s = np.sum(scores,axis=1)
In [62]:
(scores.T / sum_s).T
Out[62]:
In [70]:
scores
Out[70]:
In [73]:
scores = (scores.T*1.0/sum_s).T
In [72]:
y = [2,3,0]
In [75]:
scores[range(len(scores)),y]
Out[75]:
In [76]:
scores
Out[76]:
In [77]:
scores.shape
Out[77]:
In [3]:
xrange(1e-7,1e-4,10)
In [1]:
import numpy as np
In [10]:
np.arange(1e-7,1e-5,0.01)
Out[10]:
In [27]:
np.linspace(1e-5,1e-7,10)
Out[27]:
In [2]:
x = np.array([[1,1,1,1],[2,2,2,2],[3,3,3,3]])
In [3]:
x
Out[3]:
In [4]:
x + np.array([1,1,1,1])
Out[4]:
In [5]:
f = lambda x: np.max(0,x)
In [12]:
x[0,0] = -5
In [13]:
np.maximum(x,0)
Out[13]:
In [17]:
x**2
Out[17]:
In [20]:
s = np.ones((5,4))
In [21]:
t = np.ones(5)
In [22]:
t
Out[22]:
In [25]:
s.T * t
Out[25]:
In [28]:
s.shape
Out[28]:
In [29]:
t.shape
Out[29]:
In [30]:
s*t
In [32]:
s
Out[32]:
In [33]:
t
Out[33]:
In [34]:
t.dot(s)
Out[34]:
In [ ]: