Tensorflow
Tensorflow
variables
INTRODUCTION TO TENSORFLOW IN PYTHON
Isaiah Hull
Visiting Associate Professor of Finance,
BI Norwegian Business School
What is TensorFlow?
Open-source library for graph-based numerical computation
Developed by the Google Brain Team
Collection of numbers
Speci c shape
# 0D Tensor
d0 = tf.ones((1,))
# 1D Tensor
d1 = tf.ones((2,))
# 2D Tensor
d2 = tf.ones((2, 2))
# 3D Tensor
d3 = tf.ones((2, 2, 2))
[[[1. 1.]
[1. 1.]]
[[1. 1.]
[1. 1.]]]
tf.zeros_like() zeros_like(input_tensor)
tf.ones_like() ones_like(input_tensor)
# Define a variable
a0 = tf.Variable([1, 2, 3, 4, 5, 6], dtype=tf.float32)
a1 = tf.Variable([1, 2, 3, 4, 5, 6], dtype=tf.int16)
# Define a constant
b = tf.constant(2, tf.float32)
Isaiah Hull
Visiting Associate Professor of Finance,
BI Norwegian Business School
What is a TensorFlow operation?
# Define tensors
A0 = ones(1)
A31 = ones([3, 1])
A34 = ones([3, 4])
A43 = ones([4, 3])
Isaiah Hull
Visiting Associate Professor of Finance,
BI Norwegian Business School
Overview of advanced operations
We have covered basic operations in TensorFlow
add() , multiply() , matmul() , and reduce_sum()
# Define x
x = tf.Variable(-1.0)
-2.0