Tensorflow/Tensorflow for R
기본 자료 구조 : 텐서
딥스탯
2017. 6. 6. 12:00
출처
http://jorditorres.org/first-contact-with-tensorflow/#cap3 (First contact with tensorflow)
https://tensorflow.rstudio.com/basic_usage.html#tensors (TensorFlow™ for R)
https://www.tensorflow.org/programmers_guide/dims_types (TensorFlow™)
텐서플로와 파이썬 자료형
Data_type | Python_type | Description |
---|---|---|
DT_FLOAT | tf.float32 | 32비트 실수 |
DT_DOUBLE | tf.float64 | 64비트 실수 |
DT_INT8 | tf.int8 | 8비트 정수 |
DT_INT16 | tf.int16 | 16비트 정수 |
DT_INT32 | tf.int32 | 32비트 정수 |
DT_INT64 | tf.int64 | 64비트 정수 |
DT_UINT8 | tf.uint8 | 8비트 부호없는 정수 |
DT_UINT16 | tf.uint16 | 16비트 부호없는 정수 |
DT_DTSTRING | tf.string | 문자형 |
DT_BOOL | tf.bool | 논리형 |
DT_COMPLEX664 | tf.complex64 | 64비트 복소수. 실수파트 32비트, 복소수파트 32비트 |
DT_COMPLEX128 | tf.complex128 | 128비트 복소수. 실수파트 64비트, 복소수파트 64비트 |
DT_QINT8 | tf.qint8 | 양자화 계산에 사용되는 8비트 정수 |
DT_QINT32 | tf.qint32 | 양자화 계산에 사용되는 32비트 정수 |
DT_QUINT8 | tf.quint8 | 양자화 계산에 사용되는 부호없는 8비트 정수 |
랭크, 파이썬 예제, R 예제
Rank | Math_entity | Python_example | R_example |
---|---|---|---|
0 | Scalar (magnitude only) | s=483 | s<-483 |
1 | Vector (magnitude and direction) | v=[1.1,2.2,3.3] | v<-c(1.1,2.2,3.3) |
2 | Matrix (table of numbers) | m=[[1,2,3],[4,5,6],[7,8,9]] | m<-1:9 ; dim(m)<-c(3,3) |
3 | 3-Tensor (cube of numbers) | t=[[[[2],[4],[6]],[[8],[10],[12]],[[14],[16],[18]]] | t<-2*(1:9) ; dim(t)<-c(1,3,3) |
n | n-Tensor (you get the idea) | … | … |
구조, 랭크, 차원번호, 예제
Rank | Shape | Dimension_number | Example |
---|---|---|---|
0 | [] | 0-D | A 0-D tensor. A scalar. |
1 | [D0] | 1-D | A 1-D tensor with shape[5]. |
2 | [D0,D1] | 2-D | A 2-D tensor with shape [3,4]. |
3 | [D0,D1,D2] | 3-D | A 3-D tensor with shape [1,4,3]. |
n | [D0,D1,…,Dn-1] | n-D | A tensor with shape [D0,D1,…,Dn-1]. |
API Reference
Python | R | Examples |
---|---|---|
Scalar | Single-element vector | 1, 1L, TRUE, “foo” |
List | Multi-element vector | c(1.0, 2.0, 3.0), c(1L, 2L, 3L) |
Tuple | List of multiple types | list(1L, TRUE, “foo”) |
Dict | Named list or dict | list(a=1L, b=2.0), dict(x=x_data) |
NumPy ndarray | Matrix/Array | matrix(c(1,2,3,4), nrow=2, ncol=2) |
None, True, False | NULL, TRUE, FALSE | NULL, TRUE, FALSE |