tensorflow2.0 基础一 常用数据类型及转换

本文介绍了TensorFlow 2.0中的核心概念——Tensor,包括Tensor的数据类型如int, float, double和bool,创建Tensor的方法,检查Tensor类型,以及Tensor与bool、int之间的转换。特别强调了tf.Variable虽然不是标准的Tensor,但在需要判断时应使用tf.is_tensor。" 125701163,7432000,树模型可解释性:从局部到全局的理解,"['人工智能', '机器学习', '数据科学', '模型解释', '深度学习']
摘要由CSDN通过智能技术生成

Tensor 是什么

scalar: 1.1
vector: [1.1],[1.1,2.2,...]
matrix: [[1.1,2.2],[3.3,4.4],[5.5,6.6]]
tensor: rank > 2

以上都可以叫做tensor

TF数据类型

  • int, float, double
  • bool
  • string

Create Tensor

In[3]: tf.constant(1)
Out[3]: <tf.Tensor: id=0, shape=(), dtype=int32, numpy=1>

In[4]: tf.constant(1.)
Out[4]: <tf.Tensor: id=6, shape=(), dtype=float32, numpy=1.0>

In[5]: tf.constant(2.2,dtype=tf.int32)
Out[5]: TypeError: Cannot convert provided value to EagerTensor. Provided value: 2.2 Requested dtype: int32

In[6]: tf.constant(2., dtype=tf.double)
Out[6]: <tf.Tensor: id=25, shape=(), dtype=float64, numpy=2.0>

In[7]: tf.constant([True,False])
Out[7]: <tf.Tensor: id=39, shape=(2,), dtype=bool, numpy=array([ True, False])&
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值