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

边栏推荐
猜你喜欢
随机推荐
knn到底咋回事?
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
安科瑞支持以太网通讯、profibus通讯嵌入式电能表APM指导性技术要求-Susie 周
hdu 1503 Advanced Fruits(最长公共子序列的应用)
SecureCRT 设置超时自动断开连接时长
Can I make a TCP connection without accept?
Week 8 Deep learning for object detection
MySQL跨表、多表更新SQL语句总结
小黑leetcode之旅:94. 二叉树的中序遍历(补充Morris 中序遍历)
MySQL Notes-06 Basic SQL Operations
matlab neural network ANN classification
DSPE-PEG-PDP, DSPE-PEG-OPSS, phospholipid-polyethylene glycol-mercaptopyridine reduce the immunogenicity of peptides
LoRa Basics无线通信技术和应用案例详解
Number of daffodils within a thousand
Two methods of implementing inverted strings in C language
【随笔】致19期的小伙伴们
MySQL:错误1153(08S01):得到的数据包大于“ max_allowed_packet”字节
POWER SOURCE ETA埃塔电源维修FHG24SX-U概述
Word怎么制作一张标准的答题卡?
hdu 1333 Smith Numbers(暴力思路)









