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 -------------------------------------- ...
随机推荐
- django6-orm进阶操作
1.创建django环境的脚本 在自定义脚本中操作orm ,但是自定义脚本中不具备django的环境 ###test.py 脚本,引入django的环境即可使用orm操作数据库import os if ...
- Spring高频面试题,你能答的上哪些?(高级篇)
1.什么是 Spring 框架?Spring 框架有哪些主要模块? 2.使用 Spring 框架能带来哪些好处? 3.什么是控制反转(IOC)?什么是依赖注入? 4.请解释下 Spring 框架中的 ...
- python中的随机模块random
random模块是 python 中为随机数所使用的模块 ```import random # 随机生成0-1范围内的随机浮点数i = random.random()print(i) # 随机生成范围 ...
- Django之ContentType,GenericRelation, GenericForeignKey
contenttypes 是Django内置的一个应用,可以追踪项目中所有app和model的对应关系,并记录在ContentType表中. models.py文件的表结构写好后,通过makemigr ...
- centos7虚拟机端口命令
cat /etc/redhat-release # 查看centos 版本 Centos7端口常见命令 虚拟机新开了5005端口,系统内部是显示开了的,但是外部不能访问端口. 一些需要用到的命令: ...
- RabbitMQ的消息传输保障三个层级
这里只简单介绍一下三个层级,笔记摘录自<RabbitMQ实战指南>朱忠华作者 消息可靠传输一般是业务系统接入消息中间件时候首要考虑的问题,一般消息中间件的消息传输保障分为三个层级 1 A ...
- oracle 定时运行存储过程的实现
是基于PL/SQL 可视化工具的实现: 首先,先编写一个存储过程 点击procedure,右键新建,填写一个你编写的存储过程的名字: 如果是对正常的表进行操作,那么直接在begin和end ...
- linux字体,bashrc的问题的解决
0.查看文件 :set ff #查看文件类型 这里是fileformat=unix :set ff=dos 设置为dos模式, 也可以用 sed -i 's/$/\r/' :set ff=unix 设 ...
- 用Node.js给邮箱发送邮件
首先我们需要做的是下载发送邮件的包 cnpm install nodemailer --save 然后写发送邮件的代码,代码如下: 实现原理是:用你的邮箱给其他邮箱发送邮件,所以这里需要填写你的邮箱和 ...
- Redis与python
一.Redis介绍 Redis是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库(非关系型数据库). 本质:将数据保存在内存中. 用途:缓存.消息队列. 1.Redis的特点 R ...