tf.string_分裂对于弦的张量

2024-03-28 19:30:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个张量

x = [b'1 2 3 4 5'
     b'3 2 1'
     b'1 2']

我怎样才能把这个张量的单串分解成数字?当我应用tf.string_split(x)时,我得到以下错误:

TypeError: Failed to convert object of type <class 'tensorflow.python.framework.sparse_tensor.SparseTensor'> to Tensor. Contents: SparseTensor(indices=Tensor("StringSplit_1:0", shape=(?, 2), dtype=int64), values=Tensor("StringSplit_1:1", shape=(?,), dtype=string), dense_shape=Tensor("StringSplit_1:2", shape=(2,), dtype=int64)). Consider casting elements to a supported type.

当我尝试使用tf.string_split(x).values时,我得到以下张量: x = [b'1' b'2' b'3' b'4' b'5' b'3 b'2 b'1' b'1 b'2']

这不是我想要的,因为数字属于一起的信息已经消失了。我想要的是这样的东西

^{pr2}$

在下一步中用tf.string_to_number将这些转换为int32。在

有人能帮我吗?在


Tags: tostringtftype数字splitvaluestensor