Learning Tensorflow 基本数据

2020-08-21  本文已影响0人  轻骑兵1390

1. 基本类型 Tensor

Tensorflow的基本数据类型为tf.Tensor支持

tf.Tensor和NumPy的区别在于

  1. Tensor可以由GPU, TPU运算.
  2. Tensor 是不变的(immutable).

2. NumPy 和 Tensor

NumPy 和 Tensor两者之间的转换可以自动转换.

import numpy as np

ndarray = np.ones([3, 3])

print("TensorFlow operations convert numpy arrays to Tensors automatically")
tensor = tf.multiply(ndarray, 42)
print(tensor)


print("And NumPy operations convert Tensors to numpy arrays automatically")
print(np.add(tensor, 1))

print("The .numpy() method explicitly converts a Tensor to a numpy array")
print(tensor.numpy())

Dataset

tf.data.Dataset 构建将数据输送给模型的pipe.

上一篇 下一篇

猜你喜欢

热点阅读