當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tf.make_ndarray用法及代碼示例

從張量創建一個 numpy ndarray。

用法

tf.make_ndarray(
    tensor
)

參數

  • tensor 一個張量原型。

返回

  • 具有張量內容的 numpy 數組。

拋出

  • TypeError 如果張量的類型不受支持。

創建一個與張量具有相同形狀和數據的 numpy ndarray。

例如:

# Tensor a has shape (2,3)
a = tf.constant([[1,2,3],[4,5,6]])
proto_tensor = tf.make_tensor_proto(a)  # convert `tensor a` to a proto tensor
tf.make_ndarray(proto_tensor) # output:array([[1, 2, 3],
#                                              [4, 5, 6]], dtype=int32)
# output has shape (2,3)

相關用法


注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.make_ndarray。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。