tf.reduce_sum() and tf.where()的用法
import tensorflow as tf
import numpy as np
sess=tf.Session()
a=np.ones((5,6))
c=tf.cast(tf.reduce_sum(a, axis=1),tf.bool) # tf.reduce_sum 表示按照axis方向求和
c=sess.run(c)
print('c=',c)
print('c.shape',c.shape)
k=tf.where(c) # 因为返回的是索引值为列表中
k=sess.run(k)
print('k=',k)
print('k.shape=',k.shape)
k_compare=tf.where(c)[:, 0]
k_compare=sess.run(k_compare)
print('k_compare=',k_compare)
print('k_compare.shape=',k_compare.shape) 结果如下:

tf.reduce_sum() and tf.where()的用法的更多相关文章
- tf.reduce_sum tensorflow维度上的操作
tensorflow中有很多在维度上的操作,本例以常用的tf.reduce_sum进行说明.官方给的api reduce_sum( input_tensor, axis=None, keep_dims ...
- tf.trainable_variables() and tf.all_variables()
tf.trainable_variables() 返回的是 所有需要训练的变量列表 tf.all_variables() 返回的是 所有变量的列表 v = tf.Variable(0, name=' ...
- 1、求loss:tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits, labels, name=None))
1.求loss: tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits, labels, name=None)) 第一个参数log ...
- TensorFlow函数:tf.reduce_sum
tf.reduce_sum 函数 reduce_sum ( input_tensor , axis = None , keep_dims = False , name = None , reducti ...
- tf.concat, tf.stack和tf.unstack的用法
tf.concat, tf.stack和tf.unstack的用法 tf.concat相当于numpy中的np.concatenate函数,用于将两个张量在某一个维度(axis)合并起来,例如: a ...
- tf.reduce_sum函数
>>> x=[[1,2,3],[23,13,213]] >>> xx=tf.reduce_sum(x) >>> sess.run(xx) 255 ...
- tf.reduce_sum()_tf.reduce_mean()_tf.reduce_max()
根据官方文档: reduce_sum应该理解为压缩求和,用于降维 tf.reduce_sum(input_tensor,axis=None,keepdims=None,name=None,reduct ...
- tf.nn.softmax & tf.nn.reduce_sum & tf.nn.softmax_cross_entropy_with_logits
tf.nn.softmax softmax是神经网络的最后一层将实数空间映射到概率空间的常用方法,公式如下: \[ softmax(x)_i=\frac{exp(x_i)}{\sum_jexp(x_j ...
- 【转载】 tf.ConfigProto和tf.GPUOptions用法总结
原文地址: https://blog.csdn.net/C_chuxin/article/details/84990176 -------------------------------------- ...
随机推荐
- JavaScript初探 二 (了解数据)
JavaScript初探 (二) JavaScript 事件 HTML事件 HTML事件是可以在浏览器或用户做的某些事情 HTML事件的例子: HTML网页完成加载 HTML输入字段被修改 HTML按 ...
- [20190515]热备份模式与rman冲突.txt
[20190515]热备份模式与rman冲突.txt --//别人的系统做dg时打开热备份模式,忘记关闭,做rman备份时报错.做一个记录.--//实际上也怪自己,实施时没有讲清楚.通过例子说明: 1 ...
- Centos7 环境安装初始化
安装系统 默认分区 磁盘分配(以20G为例): Boot分区:引导分区系统启动的必要核心文件,建议1G Var分区:存放log文件,不分则在/下,建议1G Home分区:存放用户数据,一般都比较大,建 ...
- CodeForces 1236D(模拟)
题意 https://vjudge.net/problem/CodeForces-1236D 最近,爱丽丝得到了一个新玩偶.它甚至可以走路! 爱丽丝为玩偶建造了一个迷宫,并想对其进行测试.迷宫具有n行 ...
- 4. gitlab 安装、项目创建
官网: https://about.gitlab.com/ https://docs.gitlab.com/omnibus/maintenance/README.html#get-service-st ...
- Pwn-Smashes
题目地址 https://dn.jarvisoj.com/challengefiles/smashes.44838f6edd4408a53feb2e2bbfe5b229 友链 https://www. ...
- 通过Python代码操作MySQL:
pymsql / MySQLdb pymysql支持 py2/py3 MySQLdb支持py2 ORM框架 django orm ( 自己对数据连接有优化机制 ) SQLAlchemy ( 自带数据库 ...
- JDOJ1178:铺地板II
JDOJ1178:铺地板II https://neooj.com/oldoj/problem.php?id=1178 题目描述 用1 x 1和2 x 2的磁砖不重叠地铺满N x 3的地板,共有多少种方 ...
- 用Python爬取猫眼上的top100评分电影
代码如下: # 注意encoding = 'utf-8'和ensure_ascii = False,不写的话不能输出汉字 import requests from requests.exception ...
- Codeforces Round #554 (Div. 2) C 数论
https://codeforces.com/contest/1152/problem/C 题意 a和b,找到k,使得lcm(a+k,b+k)最小(a,b:1e9) 题解 设gcd=gcd(a+k,b ...