当前位置:网站首页>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)
边栏推荐
- What are the benefits of enterprise data integration?How do different industries solve the problem of data access?
- 凸集与凸函数
- Word箭头上面怎么打字
- [Generic Programming] Full Detailed Explanation of Templates
- 安科瑞无线物联网智能电表ADW300指导性技术要求-Susie 周
- 筑牢安全防线 鹤壁经济技术开发区开展安全生产培训
- laravel 表迁移报错[通俗易懂]
- L3-2 至多删三个字符 (30 分)
- 【深度学习】pix2pix GAN理论及代码实现
- Two methods of implementing inverted strings in C language
猜你喜欢
人人都可以DIY的大玩具,宏光MINIEV GAMEBOY产品力强,出行新装备
[corctf 2022] section
buuctf (Adventure 2)
[corctf 2022] 部分
hdu 1503 Advanced Fruits(最长公共子序列的应用)
数独 | 回溯-7
Lyapp exponents and bifurcation diagrams for fractional chaotic systems
上海控安SmartRocket系列产品推介(三):SmartRocket iVerifier计算机联锁系统验证工具
10个 Istio 流量管理 最常用的例子,你知道几个?
URL Protocol 网页打开应用程序
随机推荐
cad图纸怎么复制到word文档里面?Word里插CAD图怎么弄?
6 g underwater channel modeling were summarized based on optical communication
leetcode: the Kth largest element in the array
线段相交的应用
FET Mosfet Leiditech corresponds to Infineon Infineon
题解:Edu Codeforces 109(div2)
MySQL:错误1153(08S01):得到的数据包大于“ max_allowed_packet”字节
自监督学习 —— MoCo v2
人人都可以DIY的大玩具,宏光MINIEV GAMEBOY产品力强,出行新装备
PMP daily practice | didn't lost a 8.9 (including agile + multi-select)
DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified silica particles
【stack】【queue】【priority_queue】【deque】详解
knn到底咋回事?
Next second data: the transformation of the modern data stack brought about by the integration of lake and warehouse has begun
NetCore路由的Endpoint模式
Referenced file contains errors 完美解决方法
Interviewer: How to deal with Redis big key?
安科瑞无线物联网智能电表ADW300指导性技术要求-Susie 周
Acrel5000web能耗系统在某学院的应用-Susie 周
定投的基金