当前位置:网站首页>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)

边栏推荐
- Don't tell me to play, I'm taking the PMP exam: what you need to know about choosing an institution for the PMP exam
- URL Protocol 网页打开应用程序
- Unity2D_背景粒子效果
- Daily practice of PMP | Do not get lost in the exam -8.8 (including agility + multiple choice)
- mysql配置参数详解[通俗易懂]
- Endpoint mode for NetCore routing
- 场效应管Mosfet之雷卯Leiditech对应英飞凌Infineon
- matlab neural network ANN classification
- 数据集成API如何成为企业数字化转型的关键?
- C语言预处理命令是什么?
猜你喜欢
![[corctf 2022] section](/img/03/ee1ead55805a2ac690ec79c675c3e6.png)
[corctf 2022] section

Word怎么制作一张标准的答题卡?

URL Protocol web page to open the application
6个规则去净化你的代码

Problems with compiling SIP with QGIS

DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine reduce the immunogenicity of peptides

SQL语句及索引的优化

Simulation of Water Temperature Control System Based on Fuzzy PID Controller

DSPE-PEG-Azide,DSPE-PEG-N3,磷脂-聚乙二醇-叠氮可和DBCO直接反应

人人都可以DIY的大玩具,宏光MINIEV GAMEBOY产品力强,出行新装备
随机推荐
Unity_平滑移动
浅谈Numpy中的shape、reshape函数的区别
kvm虚拟机出现启动不了,NOT available,PV大于分区
hdu 3341 Lost's revenge(dp+Ac自动机)
DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine reduce the immunogenicity of peptides
智能家居设备安全分析技术综述
必看设计干货|易知微设计师是怎么做标准可视化设计服务的?
【云原生】4.2 DevOps 精讲篇
Jmeter 使用正则表达式提取器将返回值全部保存到一个文件中
Beat the interviewer, the CURD system can also make technical content
Hessian Matrix 海森矩阵
PMP每日一练 | 考试不迷路-8.8(包含敏捷+多选)
[corctf 2022] 部分
mysql配置参数详解[通俗易懂]
Puyuan Jingdian turned losses into profits in the first half of the year, and high-end products continued to develop!Are you optimistic about "Huawei" in the instrument industry?
UE4_定序器控制蓝图对象
linux定时执行sql文件[通俗易懂]
LoRa无线技术在物联网应用市场的概况和发展
POWER SOURCE ETA埃塔电源维修FHG24SX-U概述
DSPE-PEG-Azide, DSPE-PEG-N3, phospholipid-polyethylene glycol-azide can react directly with DBCO