【问题标题】:TF2.0: How to create a tensor with numpy attributeTF2.0:如何创建具有 numpy 属性的张量
【发布时间】:2019-10-16 15:55:30
【问题描述】:

我正在尝试创建一个具有 numpy 属性的张量并尝试了这个:

tensor1 = tf.reshape(tf.constant([100, 100, 100], dtype=tf.int64), (-1, 1))

print(tensor1)

 #tensor1
 tf.Tensor(
[[100]
 [100]
 [100]], shape=(3, 1), dtype=int64)

但是输出没有显示张量 ID 或 numpy 属性,其中值将是一个数组。如何创建该格式的张量

【问题讨论】:

    标签: python-3.x numpy tensorflow tensorflow2.0


    【解决方案1】:

    还是有numpy的方法,直接调用吧:

    tensor1 = tf.reshape(tf.constant([100, 100, 100], dtype=tf.int64), (-1, 1))
    
    print(tensor1)
    print(tensor1.numpy())
    

    还有,看看两者的区别

    print(str(tensor1))
    

    print(repr(tensor1))
    

    【讨论】:

      猜你喜欢
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      • 1970-01-01
      相关资源
      最近更新 更多