Created
November 3, 2016 14:37
-
-
Save BinRoot/8d550d42af2425870a9ffed0076a718e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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