美文网首页
Learning Tensorflow 基本数据

Learning Tensorflow 基本数据

作者: 轻骑兵1390 | 来源:发表于2020-08-21 10:06 被阅读0次

1. 基本类型 Tensor

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

  • tf.add
  • tf.square
  • tf.reduce_sum 求和
  • tf.matmul 矩阵相乘
    这些操作产生tf.Tensor的对象, 可以使用.shapedtype表示维数和尺度.

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.

相关文章

网友评论

      本文标题:Learning Tensorflow 基本数据

      本文链接:https://www.haomeiwen.com/subject/jdayjktx.html