# -*- coding: utf-8 -*-
"""
Created on Mon Apr 22 21:02:02 2019 @author: a
""" # -*- coding: utf-8 -*-
"""
Created on Sat Dec 1 16:53:26 2018 @author: a
"""
import tensorflow as tf
############创建三维矩阵
x = tf.placeholder(tf.int32,shape=[],name="input")
y = tf.placeholder(tf.int32,shape=[],name="input2")
z = tf.placeholder(tf.int32,shape=[],name="input3")
matrix_element_num=x*y*z
batch_sentence_nodes_vectors=tf.zeros(matrix_element_num,tf.float64)
batch_sentence_nodes_vectors=tf.reshape(batch_sentence_nodes_vectors,[x,y,z])
sess = tf.Session()
print (tf.shape(x))
xiaojie=sess.run([x,y,z],feed_dict={x:7,y:8,z:9})
print(xiaojie)
xiaojie2=sess.run(batch_sentence_nodes_vectors,feed_dict={x:7,y:8,z:9})
############创建三维矩阵
############我们目前能够做的就是,指定第一维度的值,然后将一个二维矩阵,必须小于三维矩阵的第二维度和第三维度,替换掉一整个剖面。
#def modify_one_column(tensor,columnTensor,index,numlines,numcolunms):#index也是tensor
def modify_one_profile(tensor,_2DmatrixTensor,index_firstDimension,size_firstDimension,size_secondDimension,size_thirdDimension):
##tensor为三维矩阵
##首先,我们用index_firstDimenion取出整个tensor在第一维度取值index_firstDimenion的剖面,然后分为剖面左侧部分,剖面右侧部分,然后将取出的剖面替换成二维矩阵
_2DmatrixTensor=tf.expand_dims(_2DmatrixTensor,axis=0) #扩展成为三维
new_tensor_left=tf.slice(tensor, [0,0,0], [index_firstDimension,size_secondDimension,size_thirdDimension]) #剖面左侧部分
new_tensor_right=tf.slice(tensor, [index_firstDimension+1,0,0], [size_firstDimension-index_firstDimension-1,size_secondDimension,size_thirdDimension]) #剖面右侧部分
new_tensor=tf.concat([new_tensor_left,_2DmatrixTensor,new_tensor_right],0)
return new_tensor_left,new_tensor_right,new_tensor
#下面测试将一个不够维度的二维矩阵补齐按指定维度补齐
def buqi_2DmatrixTensor(_2DmatrixTensor,lines,columns,targetlines,targetcolumns):
#首先在列上补齐
buqi_column=tf.zeros([lines,targetcolumns-columns],dtype=tf.float64)
_2DmatrixTensor=tf.concat([_2DmatrixTensor,buqi_column],axis=1)
buqi_line=tf.zeros(shape=[targetlines-lines,targetcolumns],dtype=tf.float64)
_2DmatrixTensor=tf.concat([_2DmatrixTensor,buqi_line],axis=0)
return _2DmatrixTensor
#_2DmatrixTensor=tf.ones(y*z,tf.float64)
#_2DmatrixTensor=tf.reshape(_2DmatrixTensor,[y,z])
size_firstDimension=tf.constant(7,tf.int32)
size_secondDimension=tf.constant(8,tf.int32)
size_thirdDimension=tf.constant(9,tf.int32) #_2DmatrixTensor=tf.ones(1*2,tf.float64)
#_2DmatrixTensor=tf.reshape(_2DmatrixTensor,[1,2])
#lines=tf.constant(1,tf.int32)
#columns=tf.constant(2,tf.int32)
#_2DmatrixTensor=buqi_2DmatrixTensor(_2DmatrixTensor,lines,columns,size_secondDimension,size_thirdDimension) #_2DmatrixTensor=tf.ones(8*2,tf.float64)
#_2DmatrixTensor=tf.reshape(_2DmatrixTensor,[8,2])
#lines=tf.constant(8,tf.int32)
#columns=tf.constant(2,tf.int32)
#_2DmatrixTensor=buqi_2DmatrixTensor(_2DmatrixTensor,lines,columns,size_secondDimension,size_thirdDimension) _2DmatrixTensor=tf.ones(1*9,tf.float64)
_2DmatrixTensor=tf.reshape(_2DmatrixTensor,[1,9])
lines=tf.constant(1,tf.int32)
columns=tf.constant(9,tf.int32)
_2DmatrixTensor=buqi_2DmatrixTensor(_2DmatrixTensor,lines,columns,size_secondDimension,size_thirdDimension)
## for index in range(7):
index_tensor=tf.constant(index,tf.int32)
new_tensor_left,new_tensor_right,batch_sentence_nodes_vectors=modify_one_profile(batch_sentence_nodes_vectors,_2DmatrixTensor,index_tensor,size_firstDimension,size_secondDimension,size_thirdDimension)
print (sess.run(batch_sentence_nodes_vectors,feed_dict={x:7,y:8,z:9}))

  

12 tensorflow实战:修改三维tensor矩阵的某个剖面的更多相关文章

  1. TensorFlow 实战(四)—— tensor 的认识

    tensorflow,即是 tensor flows,在 computation graph 中 flows(流动)的不是别人,正是 tensor: 1. tensor 基本属性 tensor 的名字 ...

  2. TensorFlow实战之实现自编码器过程

    关于本文说明,已同步本人另外一个博客地址位于http://blog.csdn.net/qq_37608890,详见http://blog.csdn.net/qq_37608890/article/de ...

  3. TensorFlow实战之实现AlexNet经典卷积神经网络

    本文根据最近学习TensorFlow书籍网络文章的情况,特将一些学习心得做了总结,详情如下.如有不当之处,请各位大拿多多指点,在此谢过. 一.AlexNet模型及其基本原理阐述 1.关于AlexNet ...

  4. 1 如何使用pb文件保存和恢复模型进行迁移学习(学习Tensorflow 实战google深度学习框架)

    学习过程是Tensorflow 实战google深度学习框架一书的第六章的迁移学习环节. 具体见我提出的问题:https://www.tensorflowers.cn/t/5314 参考https:/ ...

  5. Tensorflow实战(二):Discuz验证码识别

    一.前言 验证码是根据随机字符生成一幅图片,然后在图片中加入干扰象素,用户必须手动填入,防止有人利用机器人自动批量注册.灌水.发垃圾广告等等 . 验证码的作用是验证用户是真人还是机器人. 本文将使用深 ...

  6. TensorFlow实战之Softmax Regression识别手写数字

         关于本文说明,本人原博客地址位于http://blog.csdn.net/qq_37608890,本文来自笔者于2018年02月21日 23:10:04所撰写内容(http://blog.c ...

  7. TensorFlow 实战之实现卷积神经网络

    本文根据最近学习TensorFlow书籍网络文章的情况,特将一些学习心得做了总结,详情如下.如有不当之处,请各位大拿多多指点,在此谢过. 一.相关性概念 1.卷积神经网络(ConvolutionNeu ...

  8. [Tensorflow实战Google深度学习框架]笔记4

    本系列为Tensorflow实战Google深度学习框架知识笔记,仅为博主看书过程中觉得较为重要的知识点,简单摘要下来,内容较为零散,请见谅. 2017-11-06 [第五章] MNIST数字识别问题 ...

  9. 《TensorFlow实战》中AlexNet卷积神经网络的训练中

    TensorFlow实战中AlexNet卷积神经网络的训练 01 出错 TypeError: as_default() missing 1 required positional argument: ...

随机推荐

  1. 搜索类网站记录 && 代理服务器

    搜索类网站记录 && 代理服务器 技巧 1.使用site   我们在搜索的时候,其实不全依赖搜索引擎也是可以的, 比如我们要搜索一个 “中国” ,可以在搜索框输入   中国  site ...

  2. Spring Security构建Rest服务-1201-Spring Security OAuth开发APP认证框架之实现服务提供商

    实现服务提供商,就是要实现认证服务器.资源服务器. 现在做的都是app的东西,所以在app项目写代码  认证服务器: 新建 ImoocAuthenticationServerConfig 类,@Ena ...

  3. Centos 6.5下的OPENJDK卸载和SUN的JDK安装、环境变量配置

    不多说,直接上干货! 说明 图形界面安装,会自带有Centos6.5自带的OPRNJDK!!! *********************************自带的OPENJDK的卸载****** ...

  4. js时间戳差值转日期格式

    <script> function getRemainderTime (startTime){     var s1 = new Date(startTime.replace(/-/g,  ...

  5. java学习-java.lang.Math随机数生成

    java中的随机数,java.lang.Math.random()和java.util.Random.nextDouble() Math.random()方法是生成0.0---1.0区域内的随机数,每 ...

  6. MySQL decimal unsigned 更新负数不报错却为0

    今天在验证接口的并发问题时,把之前通过 redis 解决的并发压力转移到 mysql 上(redis 在 set 保存数据和数据过期需要去向数据库获取时存在时延,会存在空挡造成大并发多插入数据的风险: ...

  7. C#循环读取文件流,按行读取

    public Dictionary<string,string> GetSourceDisksElements(String section) { section = "[&qu ...

  8. 数据序列化导读(2)[YAML]

    上一节讲了JSON, 这一节将介绍YAML.可以认为,YAML是JSON的超集,但是更加简单易用,适合人类阅读和书写. 1.  什么是YAML? YAML是YAML Ain't Markup Lang ...

  9. Oracle 12c 操作 CDB PDB

    CREATE TRIGGER open_all_pdbs AFTER STARTUP ON DATABASE BEGIN EXECUTE IMMEDIATE 'alter pluggable data ...

  10. Ubuntu16.04 LTS上安装Go1.10

    原因 Ubuntu资源库上默认使用的是Go1.6.2版本,给最新版本代码编译带来了不少问题.本文就记录下在Ubuntu下直接安装Go最新版1.10的步骤. 准备工作 1.卸载已有版本 # 卸载已经安装 ...