Tensorflow函数

最近在看tensorflow,顺便记录下遇到的常用函数。

2018.12.10 更新tf.eval   tf.equal   tf.cast   tf.argmax

# -*- coding: utf-8 -*-
"""
Created on Sat Dec  8 22:56:06 2018

@author: Administrator
"""
#可以用help("fun")查看具体的参数说明    
#help(tf.argmax)axis

import tensorflow as tf
import numpy as np
#tf.equal 对比两个矩阵或者向量是否相等,相等返回True,不相等返回False,返回值是bool
#tf.cast 将X的数据格式转换成指定的格式
A = tf.constant([[1,2,3,4,5]])
B = tf.constant([[1,3,3,2,5]])
#eval 相当于tf.Session.run()
#tf.equal(A,B).eval()等同于 sess.run(tf.equal(A,B))
with tf.Session():
    eval_equal=tf.equal(A,B).eval()
    print("eval:",eval_equal)    

with tf.Session() as sess:
    equal=sess.run(tf.equal(A,B))
    print(equal)
    #[[ True False  True False  True]]
    cast=sess.run(tf.cast(equal,tf.float32))
    print(cast)
    #[[ 1.  0.  1.  0.  1.]]

#tf.argmax 返回最大值的下标 axis=0:代表列,1:代表行
C = tf.constant([[1,2,3],[4,5,6],[5,4,3],[3,4,2]])
with tf.Session() as sess:
    argmax_0=sess.run(tf.argmax(C,axis=0))
    argmax_1=sess.run(tf.argmax(C,axis=1))
    print(argmax_0)
    #[2 1 1] 
    print(argmax_1)
    #[2 2 0 1]
    '''
     1 2 3
     4 5 6
     5 4 3
     3 4 2
     '''

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值