# tensor 数据类型 转换 方法 mytf = np.arange(5) # 区别标准的python中的range(10)函数 print(mytf) print(mytf.dtype) # np.arange()函数默认为64位整型,转化为32位 可以使用如下: mytf1 = tf.convert_to_tensor(mytf) # 将np存储数据类型转化为tensor类型打印出来为int32位 mytf2 = tf.convert_to_tensor(mytf, dtype=tf.int32) # 将tensor的64位转化位32位 print(mytf2) print(mytf1) # another method to change datatype:cast函数 mytf3 = tf.cast(mytf, dtype=tf.float32) # 转化为浮点型的tensor数据 print(mytf3) mytf4 = tf.cast(mytf3, dtype=tf.double) # 浮点型转化为浮点双精度型 print(mytf4) print(tf.cast(mytf4, dtype=tf.int32)) # 将浮点双精度数据转化整型数据int32
tensor数据类型转换方法:
tf.cast(tensor,dtype='')
或
tf.convert_to_tensor(mytf, dtype=tf.int32)
如果对python或者tensor感兴趣,欢迎添加微信 wangqime 作为新手 交流讨论也算是加深印象的一个方式
已有2位网友发表了看法:
发表评论