yongyong-e
[TensorFlow] Tensor 본문
1) Tensor 자료형을 constant를 이용하여 생성
1 2 3 4 | import tensorflow as tf const = tf.constant('Hello Tensorflow!!!') print(const) | cs |
>> Tensor("Const:0", shape=(), dtype=string)
2) Tensor 자료형은 python에서 호출 불가능, 따라서 Tensorflow에서 제공하는 Session() 함수의 run을 통해 호출 가능
1 2 3 4 5 6 7 | import tensorflow as tf const = tf.constant('Hello Tensorflow!!!') with tf.Session() as sess: _const = sess.run(const) print(_const) | cs |
>> b'Hello Tensorflow!!!'
3) Tensorflow를 사용한 Matrix 연산 예제
1 2 3 4 5 6 7 8 9 10 11 12 | import tensorflow as tf mat1 = [[1, 2, 3,], [4, 5, 6], [7, 8, 9]] mat2 = [[2, 2, 2,], [2, 2, 2], [2, 2, 2]] t_mat1 = tf.constant(mat1) t_mat2 = tf.constant(mat2) result = tf.matmul(t_mat1, t_mat2) with tf.Session() as sess: _result = sess.run(result) | cs |
>> [[12 12 12]
[30 30 30]
[48 48 48]]
Rank
Rank |
Math entity |
Python example |
0 |
Scalar (magnitude only) |
s = 123 |
1 |
Vector (magnitude and direction) |
v = [1.1 , 2.2] |
2 |
Matrix (table of numbers) |
m = [[1, 2, 3], [4, 5, 6]] |
3 |
3-Tensor (cube of numbers) |
t = [[[1], [2], [3]], [[4], [5], [6]], [[7], [8], [9]]] |
n |
n-Tensor (you get the idea) |
. . . . |
Shape
Rank |
Shape |
Dimension number |
Example |
0 |
[] |
0-D |
A 0-D tensor. A scalar. |
1 |
[D0] |
1-D |
A 1-D tensor with shape [3]. |
2 |
[D0, D1] |
2-D |
A 2-D tensor with shape [1, 2]. |
3 |
[D0, D1, D2] |
3-D |
A 3-D tensor with shape [1, 2, 3]. |
n |
[D0, D1, ... Dn-1] |
n-D |
A tensor with shape [D0, D1, ... Dn-1]. |
Type
Data type |
Python type |
Description |
DT_FLOAT |
tf.float32 |
32 bits floating point. |
DT_DOUBLE |
tf.float64 |
64 bits floating point. |
DT_INT8 |
tf.int8 |
8 bits signed integer. |
DT_INT16 |
tf.int16 |
16 bits signed integer. |
DT_INT32 |
tf.int32 |
32 bits signed integer. |
DT_INT34 |
tf.int64 |
64 bits signed integer. |
'머신러닝 > TensorFlow' 카테고리의 다른 글
[TensorFlow] Flags (0) | 2018.06.30 |
---|---|
[TensorFlow] 로그 필터링 (0) | 2018.06.30 |
[TensorFlow] Tested source configurations (0) | 2017.11.23 |
[TensorFlow] Linear Regression (0) | 2017.09.11 |
[TensorFlow] Basic (0) | 2017.09.11 |