Skip to content

Instantly share code, notes, and snippets.

@BinRoot
Created November 3, 2016 14:37
Show Gist options
  • Save BinRoot/8d550d42af2425870a9ffed0076a718e to your computer and use it in GitHub Desktop.
Save BinRoot/8d550d42af2425870a9ffed0076a718e to your computer and use it in GitHub Desktop.
import tensorflow as tf
# We’ll use NumPy matrices in TensorFlow
import numpy as np
# Define a 2x2 matrix in 3 different ways
m1 = [[1.0, 2.0],
[3.0, 4.0]]
m2 = np.array([[1.0, 2.0],
[3.0, 4.0]], dtype=np.float32)
m3 = tf.constant([[1.0, 2.0],
[3.0, 4.0]])
# Print the type for each matrix
print(type(m1))
print(type(m2))
print(type(m3))
# Create tensor objects out of the different types
t1 = tf.convert_to_tensor(m1, dtype=tf.float32)
t2 = tf.convert_to_tensor(m2, dtype=tf.float32)
t3 = tf.convert_to_tensor(m3, dtype=tf.float32)
# Notice that the types will be the same now
print(type(t1))
print(type(t2))
print(type(t3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment