gpt4 book ai didi

python - 你如何获得稀疏张量中使用的张量的名称?

转载 作者:行者123 更新时间:2023-12-04 08:15:06 25 4
gpt4 key购买 nike

TensorFlow represents a sparse tensor as three separate dense tensors: indices, values, and dense_shape. In Python, the three tensors are collected into a SparseTensor class for ease of use. If you have separate indices, values, and dense_shape tensors, wrap them in a SparseTensor object before passing to the ops below.


我的问题是,给定一个稀疏张量或稀疏张量值,我如何检索每个包含张量的单独名称,即索引张量、值张量和形状张量? (除非我碰巧误解了引用文本中的解释并且这是不可能的?)

最佳答案

您可以使用以下命令访问 SparseTensor 对象中的三个张量中的每一个:

# Here some_sparse_tensor is an object of the tf.sparse.SparseTensor class
some_sparse_tensor.indices
some_sparse_tensor.values
some_sparse_tensor.dense_shape
根据文档:
https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor#attributes
您无法获得它们的“名称”,但您可以将它们分配给它们自己的变量: values_of_sparse_tensor = some_sparse_tensor.values

关于python - 你如何获得稀疏张量中使用的张量的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65746272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com