Converting from Pandas dataframe to TensorFlow tensor object

后端 未结 6 532
灰色年华
灰色年华 2020-12-31 02:48

I\'m still new to Python, Machine Learning and TensorFlow, but doing my best to jump right in head-first. I could use some help though.

My data is currently in a Pan

6条回答
  •  滥情空心
    2020-12-31 03:29

    The following works easily based on numpy array input data:

    import tensorflow as tf
    import numpy as np
    a = np.array([1,2,3])
    with tf.Session() as sess:
        tf.global_variables_initializer().run()
    
        dataVar = tf.constant(a)
        print(dataVar.eval())
    
    -> [1 2 3]
    

    Don't forget to start the session and run() or eval() your tensor object to see its content; otherwise it will just give you its generic description.

    I suspect that since your data is in the DataFrame rather than a simply array, you need to experiment with the shape parameter of tf.constant(), which you are currently not specifying, in order to help it understand the dimensionality of the DataFrame and deal with its indices, etc.?

提交回复
热议问题