【问题标题】:how to convert string Tensor to Tensor float list?如何将字符串张量转换为张量浮动列表?
【发布时间】:2018-08-04 12:07:09
【问题描述】:

所以,我的代码是这样的

    parsed_line = tf.decode_csv(line, [[0], [0], [""]])
    print(parsed_line[0])
    del parsed_line[0]
    del parsed_line[0]
    features = parsed_line
    print(parsed_line[0])

那么结果就是

    [<tf.Tensor 'DecodeCSV:0' shape=() dtype=int32>, <tf.Tensor 'DecodeCSV:1' shape=() dtype=int32>, <tf.Tensor 'DecodeCSV:2' shape=() dtype=string>]

    [<Tensor("DecodeCSV:2", shape=(), dtype=string)>]

我将给这个解码函数的 csv 是

    1, 0, 0101010010101010101010

我想要这个“0101010010101010101010”

    [0,1,0,1,0,.........] 

在张量流中

    [<Tensor("DecodeCSV:2", shape=(), dtype=string)>]

    [<tf.Tensor 'DecodeCSV:0' shape=() dtype=int32>, <tf.Tensor 'DecodeCSV:1' shape=() dtype=int32>, ............]

你对此有什么想法吗?

【问题讨论】:

    标签: tensorflow casting shape reshape tensor


    【解决方案1】:

    您可以使用tf.string_splittf.string_to_number 这样做:

    import tensorflow as tf
    
    line = tf.constant("1000111101", shape=(1,))
    b = tf.string_split(line, delimiter="").values
    c = tf.string_to_number(b, tf.int32)
    print(c)
    with tf.Session() as sess:
        print(sess.run(c))
    

    [1 0 0 0 1 1 1 1 0 1]

    【讨论】:

      猜你喜欢
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 2020-08-05
      • 2019-07-29
      • 2017-11-20
      • 2021-01-04
      相关资源
      最近更新 更多