PREV NEXT
⏮ ⏭
Shape Variables
🔎
Data types
In addition to rank and shape, tensors have a data type. The following is a
list of the data types:
32-bit
DT_FLOAT tf.float32 floating
point.
64-bit
DT_DOUBLE tf.float64 floating
point.
8-bit
DT_INT8 tf.int8 signed
integer.
16-bit
DT_INT16 tf.int16 signed
integer.
32-bit
DT_INT32 tf.int32 signed
integer.
64-bit
DT_INT64 tf.int64 signed
integer.
8-bit
DT_UINT8 tf.uint8 unsigned
integer.
Variable
length
byte
arrays.
Each
DT_STRING tf.string
element
of a
tensor is
a byte
array.
Complex
number
made of
two 32
bits
DT_COMPLEX64 tf.complex64
floating
points,
⬆
real and
imaginary
parts.
https://www.safaribooksonline.com/library/view/deep-learning-with/9781786469786/6a906be0-fd75-4416-bc13-f10aeaa6ee4b.xhtml 1/3
12/8/2017 Data types - Deep Learning with TensorFlow
Complex
number
made up
of two 64
bits
DT_COMPLEX128 tf.complex128
floating
points,
real and
imaginary
parts.
8-bit
signed
integer
DT_QINT8 tf.qint8
used in
quantized
Ops.
32-bit
signed
integer
DT_QINT32 tf.qint32
used in
quantized
ops.
8-bit
unsigned
integer
DT_QUINT8 tf.quint8
used in
quantized
ops.
import tensorflow as tf
import numpy as np
tensor_1d = np.array([1,2,3,4,5,6,7,8,9,10])
tensor_1d = tf.constant(tensor_1d)
with tf.Session() as sess:
print (tensor_1d.get_shape())
print sess.run(tensor_1d)
>>>
(10,)
[ 1 2 3 4 5 6 7 8 9 10]
To build a tensor, with variable values, use a NumPy array and pass it to
the tf.Variable constructor, the result will be a TensorFlow variable
tensor with that initial value:
import tensorflow as tf
import numpy as np
tensor_2d = np.array([(1,2,3),(4,5,6),(7,8,9)])
tensor_2d = tf.Variable(tensor_2d)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print (tensor_2d.get_shape())
print sess.run(tensor_2d)
>>>
(3, 3)
[[1 2 3]
[4 5 6]
[7 8 9]]
import tensorflow as tf
import numpy as np
interactive_session = tf.InteractiveSession()
⬆
tensor = np.array([1,2,3,4,5])
tensor = tf.constant(tensor)
print(tensor.eval())
interactive_session.close()
https://www.safaribooksonline.com/library/view/deep-learning-with/9781786469786/6a906be0-fd75-4416-bc13-f10aeaa6ee4b.xhtml 2/3
12/8/2017 Data types - Deep Learning with TensorFlow
>>>
[1 2 3 4 5]
import tensorflow as tf
import numpy as np
>>>
(3, 3, 3)
[[[ 0. 1. 2.]
[ 3. 4. 5.]
[ 6. 7. 8.]]
[[ 9. 10. 11.]
[ 12. 13. 14.]
[ 15. 16. 17.]]
Recommended / Queue / History / Topics / Tutorials / Settings / Get the App / Sign Out
© 2017 Safari. Terms of Service / Privacy Policy
PREV NEXT
⏮ ⏭
Shape Variables
https://www.safaribooksonline.com/library/view/deep-learning-with/9781786469786/6a906be0-fd75-4416-bc13-f10aeaa6ee4b.xhtml 3/3