tensorflow.python.framework.tensor_shape.TensorShape 类

TensorShape 是tensorflow中关于张量shape的类(class).

使用示例如下:

import tensorflow.compat.v1 as tf
from tensorflow.python.framework import tensor_shape
from tensorflow.python.framework import constant_op

tensor_test1=[10,10,10]
tensor_test2 = [None,10,10]

p1 = tensor_shape.as_shape(tensor_test1) # 得到的是一个类实例,该类实例包含一个属性,是 tensor_test1 的value
const = constant_op.constant(p1.as_list())

print("type(p1) = ",type(p1))
print("p1 = ",p1) # 使用p1时会自动调用p1中的value属性
print("p1.is_fully_defined() = ",p1.is_fully_defined())# is_fully_defined 是 TensorShape 类的一个内部函数
print("p1.ndims = ",p1.ndims) # ndims 也是TensorShape的一个属性值
print("p1.as_list() = ",p1.as_list()) # 把TensorShape的value属性转换成python中的list类型
print("const = ",const)

结果如下:

type(p1) =  <class 'tensorflow.python.framework.tensor_shape.TensorShape'>
p1 =  (10, 10, 10)
p1.is_fully_defined() =  True
p1.ndims =  3
p1.as_list() =  [10, 10, 10]
const =  Tensor("Const:0", shape=(3,), dtype=int32)

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值