zoukankan      html  css  js  c++  java
  • 108、TensorFlow 类型转换

    # 除了维度之外Tensorflow也有数据类型
    # 请参考 tf.DataType
    # 一个张量只能有一个类型
    # 可以使用tf.cast,将一个张量从一个数据类型转换到另一个数据类型
    # 下面代码显示的就是将一个张量的类型从integer类型转换为float类型
    import tensorflow as tf
    float_tensor = tf.cast(tf.constant([1, 2, 3]), dtype=tf.float32)
    # 当从一个python对象来创建张量的时候可以手动指定数据类型
    # 如果你不手动指定数据类型
    # TensorFlow 自动地将 Python integer 类型转换为tf.int32 并且将 python的 float类型转换为 tf.float32
    # 另外TensorFlow使用相同的规则将numpy对象转换为Array
    init = tf.global_variables_initializer()
    sess = tf.Session()
    print(sess.run(float_tensor))

    下面是类型转换的结果:

    2018-02-16 21:44:46.674417: I C:	f_jenkinsworkspace
    el-winMwindowsPY35	ensorflowcoreplatformcpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
    [ 1.  2.  3.]
  • 相关阅读:
    Postfix邮件服务
    Python
    LVS
    MFS
    Apache
    Zookeeper集群 + Kafka集群 + KafkaOffsetMonitor 监控
    shell 检测安装包
    shell ssh 批量执行
    shell 判断脚本参数
    bzoj 1500 修改区间 splay
  • 原文地址:https://www.cnblogs.com/weizhen/p/8450572.html
Copyright © 2011-2022 走看看