TensorFlow2.0教程-张量及其操作

本文是TensorFlow2.0教程的一部分,主要介绍张量的概念,包括张量的类型和形状,以及GPU加速和数据集的操作。文章强调了张量与NumPy数组的区别,并说明了如何在GPU上进行计算和设备放置策略。同时,讨论了使用tf.data.Dataset API构建数据输入管道的方法。
摘要由CSDN通过智能技术生成

TensorFlow2.0教程-张量及其操作

本文地址:https://blog.csdn.net/qq_31456593/article/details/90178004

完整tensorflow2.0教程代码请看tensorflow2.0:中文教程tensorflow2_tutorials_chinese(欢迎star)

更多TensorFlow2.0 入门教程请持续关注本博客:https://blog.csdn.net/qq_31456593/article/details/88606284

导入TensorFlow

运行tensorflow程序,需要导入tensorflow模块。
从TensorFlow 2.0开始,默认情况下会启用eager模式执行。 这为TensorFlow提供了一个更加互动的前端节。

from __future__ import absolute_import, division, print_function
import tensorflow as tf

1 Tensors

张量是一个多维数组。 与NumPy ndarray对象类似,tf.Tensor对象具有数据类型和形状。 此外,tf.Tensors可以驻留在加速器内存中(如GPU)。 TensorFlow提供了丰富的操作库(tf.add,tf.matmul,tf.linalg.inv等),它们使用和生成tf.Tensors。 这些操作会自动转换原生Python类型,例如:

print(tf.add(1,2))
print(tf.add([3,8], [2,5]))
print(tf.square(6))
print(tf.reduce_sum([7,8,9]))
print(tf.square(3)+tf.square(4))
tf.Tensor(3, shape=(), dtype=int32)
tf.Tensor([ 5 13], shape=(2,), dtype=int32)
tf.Tensor(36, shape=(), dtype=int32)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值