Tensorflowでのデータ変換、接続操作、numpyデータの垂直接続

1308 ワード

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.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]]