1.将普通的数据转换为tensor (tf.constant)
import pandas as pd
import numpy as np
import tensorflow as tf
#定义一个DataFrame类型的数据
data = pd.DataFrame(np.random.uniform(low = 0,high = 10, size = (100,90)),header = None)
#将data的类型转换为tensor
tensor = tf.constant(data)
#输出tensor的类型,注意这里的dtype是64位的浮点数
#可以通过tf.cast将数据类型转换为32位的浮点型
tf.cast(tensor, dtype = tf.float32)
2.将两个tensor拼接起来(tf.concat)
batch_size = 64
col = 363
#先定义两个占位符
x = tf.placeholder(tf.float64, [batch_size, col], name = 'originalx')
y = tf.placeholder(tf.float64, [batch_size, col], name = 'originaly')
x_y_row = tf.concat([x,y],axis = 1)#1是横向拼接
#输出x_y_row的类型
x_y_col = tf.concat([x,y],axis = 0)#0是纵向拼接
#输出x_y_col的类型
"""这里的连接tf.concat和DataFrame类型的连接pd.concat用法相同"""
3.numpy中数据的连接可以用np.vstack()函数
import numpy as np
sample1 = np.random.random(5)
sample2 = np.random.random(5)
samples = np.vstack([sample1,sample2])
print(samples)
[[0.69818292 0.51125403 0.9225995 0.35931547 0.12174736]
[0.15133575 0.12547028 0.93109742 0.11495043 0.60738572]]