In [1]:
import tensorflow as tf
In [2]:
x = tf.constant([3.0])
In [3]:
y = tf.constant([2.0])
In [4]:
sess = tf.Session()
In [5]:
sess.run([x + y, x * y, x / y, x**y])
Out[5]:
In [6]:
x = tf.range(12)
In [7]:
sess.run(x)
Out[7]:
In [8]:
sess.run(x[3])
Out[8]:
In [9]:
x.shape
Out[9]:
In [10]:
y = tf.ones(12, dtype=tf.float32)
In [11]:
sess.run(y)
Out[11]:
In [12]:
x = tf.cast(x, "float32")
In [13]:
sess.run(tf.tensordot(x, y, axes=1))
Out[13]:
In [14]:
sess.run(tf.reduce_sum(x * y))
Out[14]:
In [15]:
sess.run(tf.reduce_prod(x))
Out[15]:
In [16]:
sess.run(tf.reduce_prod(y))
Out[16]:
In [17]:
sess.run(x + y)
Out[17]:
In [18]:
sess.run(tf.reduce_sum(x))
Out[18]:
In [19]:
sess.run(tf.reduce_sum(y))
Out[19]:
In [20]:
sess.run(tf.reduce_mean(x))
Out[20]:
In [21]:
sess.run(tf.size(x))
Out[21]:
In [22]:
x_size = tf.cast(tf.size(x), "float32")
In [23]:
sess.run(tf.reduce_sum(x) / x_size)
Out[23]:
In [24]:
sess.run(tf.reshape(x, (3, 4)))
Out[24]:
In [25]:
X = tf.reshape(tf.range(12, dtype=tf.float32), (3, 4))
In [26]:
sess.run(X)
Out[26]:
In [27]:
sess.run(tf.argmax(X, 0))
Out[27]:
In [28]:
sess.run(tf.argmax(X, 1))
Out[28]:
In [29]:
sess.run(tf.reduce_sum(X, axis=0))
Out[29]:
In [30]:
sess.run(tf.reduce_sum(X, axis=1))
Out[30]:
In [31]:
sess.run(tf.reduce_sum(X, axis=[0, 1]))
Out[31]:
In [32]:
sess.run(tf.reduce_sum(X))
Out[32]:
In [33]:
Y = tf.constant([[2.0, 1, 4, 3], [1, 2, 3, 4], [4, 3, 2, 1]])
In [34]:
sess.run(Y)
Out[34]:
In [35]:
sess.run(tf.argmax(Y, 0))
Out[35]:
In [36]:
sess.run(tf.argmax(Y, 1))
Out[36]:
In [37]:
sess.run(tf.concat([X, Y], axis=0))
Out[37]:
In [38]:
sess.run(tf.concat([X, Y], axis=1))
Out[38]:
In [39]:
sess.run(X + Y)
Out[39]:
In [40]:
Z = tf.transpose(X)
In [41]:
sess.run(Z)
Out[41]:
In [42]:
sess.run(X * Y)
Out[42]:
In [43]:
A = tf.matmul(Z, tf.transpose(Z))
In [44]:
sess.run(A)
Out[44]:
In [45]:
A_symm = (A + tf.transpose(A)) / 2.0
In [46]:
sess.run(A_symm)
Out[46]:
In [47]:
sess.run(tf.equal(A_symm, tf.transpose(A_symm)))
Out[47]:
In [48]:
sum_X = tf.reduce_sum(X, axis=1, keepdims=True)
In [49]:
sess.run(sum_X)
Out[49]:
In [50]:
sess.run(X / sum_X)
Out[50]:
In [51]:
sess.run(tf.cumsum(X, axis=0))
Out[51]:
In [52]:
sess.run(tf.cumsum(X, axis=1))
Out[52]:
In [53]:
Z = tf.reshape(tf.range(24), (2, 3, 4))
In [54]:
sess.run(Z)
Out[54]:
In [55]:
a = 2
In [56]:
sess.run(a + Z)
Out[56]:
In [57]:
sess.run(a * Z)
Out[57]:
In [58]:
b = tf.constant([2.0, 1, 4, 3])
In [59]:
sess.run(b)
Out[59]:
In [60]:
sess.run(X)
Out[60]:
In [61]:
b = tf.expand_dims(b, 1)
In [62]:
sess.run(b)
Out[62]:
In [63]:
sess.run(tf.matmul(X, b))
Out[63]:
In [64]:
u = tf.constant([3.0, -4.0])
In [65]:
sess.run(tf.norm(u, ord=2))
Out[65]:
In [66]:
sess.run(tf.reduce_sum(tf.abs(u)))
Out[66]:
In [67]:
sess.run(tf.norm(u, ord=1))
Out[67]:
In [68]:
import numpy as np
In [69]:
sess.run(tf.norm(u, ord=np.inf))
Out[69]: