当前位置:网站首页>Tensorflow中使用convert_to_tensor去指定数据的类型
Tensorflow中使用convert_to_tensor去指定数据的类型
2022-08-09 21:35:00 【phac123】
简介
在Tensorflow中,可以通过convert_to_tensor去指定使用np所生成的数据;但是如果一开始生成的就是tf的tensor数据类型,再使用convert_to_tensor去转换数据类型会报错。
代码
转换成功
import tensorflow as tf
import numpy as np
a = np.arange(0, 5)
b = tf.convert_to_tensor(a, dtype = tf.int64)
a = [3, 4]
b = tf.convert_to_tensor(a, dtype = tf.int64)
a = (5, 6)
b = tf.convert_to_tensor(a, dtype = tf.float64)
print("a: ", a)
print("b: ", b)
转换失败
import tensorflow as tf
import numpy as np
a = tf.Variable(tf.constant(5))
b = tf.convert_to_tensor(a, dtype = tf.int64)
print("a: ", a)
print("b: ", b)
边栏推荐
猜你喜欢
一千以内的水仙花数
微软word怎么转换成pdf文件?微软word转换为pdf格式的方法
Ankerui supports Ethernet communication, profibus communication embedded energy meter APM guiding technical requirements-Susie Week
CMake 安装升级更高版本
kvm虚拟机出现启动不了,NOT available,PV大于分区
POWER SOURCE ETA埃塔电源维修FHG24SX-U概述
人人都可以DIY的大玩具,宏光MINIEV GAMEBOY产品力强,出行新装备
Excel如何打出正负号?Excel打出正负号的方法
DSPE-PEG-PDP,DSPE-PEG-OPSS,磷脂-聚乙二醇-巯基吡啶可减少肽的免疫原性
What to do if Windows 11 can't find Internet Explorer
随机推荐
【随笔】致19期的小伙伴们
Unity_物体自转
凸集与凸函数
题解:Edu Codeforces 109(div2)
PMP每日一练 | 考试不迷路-8.9(包含敏捷+多选)
消防安全培训|“蓝朋友”,开课了!
Word第一页空白页怎么删除?删除Word第一页空白页方法教程
json事例
Deceptive Dice(期望计算)
上海控安SmartRocket系列产品推介(三):SmartRocket iVerifier计算机联锁系统验证工具
MySQL:错误1153(08S01):得到的数据包大于“ max_allowed_packet”字节
筑牢安全防线 鹤壁经济技术开发区开展安全生产培训
【Efficient Tools】Remote Control Software ToDesk (Favorites)
Optimization of SQL Statements and Indexes
抽象类 or 接口
MySQL Notes-06 Basic SQL Operations
Word怎么制作双面席卡?使用Word制作双面席卡方法
访问控制知识
cad图纸怎么复制到word文档里面?Word里插CAD图怎么弄?
【高效工具】远程控制软件 ToDesk(收藏夹)