1. 程式人生 > >tensorflow隨筆-判斷tensor是否為小數

tensorflow隨筆-判斷tensor是否為小數

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
@author: myhaspl
@email:[email protected]
@blog:https://dmyhaspl.github.io/
"""
import tensorflow as tf
g=tf.Graph()

with g.as_default():
    x=tf.constant([[4.00, 3.33], [2.34, 7.00]])
    y=tf.cast(tf.equal(tf.cast(tf.cast(x,tf.int32),tf.float32),x),tf.int32)
with tf.Session(graph=g) as sess:
    print sess.run(y)

[[1 0]
 [0 1]]