AttributeError: 'Tensor' object has no attribute 'numpy'

添加:tf.enable_eager_execution(),開啓即時模式

A = tf.constant([[1., 2.], [3., 4.]])
B = tf.constant([[5., 6.], [7., 8.]])
tf.enable_eager_execution()
print(A.shape)      # 輸出(2, 2),即矩陣的長和寬均爲2
print(A.dtype)      # 輸出<dtype: 'float32'>
print(A.numpy())    # 輸出[[1. 2.]
                    #      [3. 4.]]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章