Tensflow学习笔记(一)——TF生成并查看数据

概要:

在Jupyer中学习TF生成并查看数据的方法。


代码:

import tensorflow as tf
import numpy as np
# 生成0和1矩阵  
x = tf.zeros([2, 2])
y = tf.ones([2, 2])
#填充单值矩阵
z = tf.fill([2, 2], 3)
#常量矩阵
c1 = tf.constant([1,2,3,4])
c2 = tf.constant(-1.0, shape=[2,2])
#生成等差数列
d1 = tf.linspace(10.0, 20.0, 5)
d2 = tf.range(10.0, 20.0, 2) 

#生成各种随机数据矩阵
#均匀分布
r1 = tf.random_uniform([2,4], minval=0.0, maxval=2.0, dtype=tf.float32, seed=1234)
#正态分布
r2 = tf.random_normal([2,3], mean=0.0, stddev=1.0, dtype=tf.float32, seed=1234)
#截断的正态分布:正太分布的值如果与均值的差值大于两倍的标准差,那就重新生成
r3 = tf.truncated_normal([2,3], mean=0.0, stddev=1.0, dtype=tf.float32, seed=1234)
#返回一个随机数序列,将value中的数据打乱输出
r4=tf.random_shuffle([[1,2,3],[4,5,6],[6,6,6]], seed=134)

with tf.Session() as sess:
    print "This is x: ", '\n',sess.run(x)
    print "This is y: ", '\n',sess.run(y)
    print "This is z: ", '\n',sess.run(z)
    print "This is c1: ",  '\n',sess.run(c1)
    print "This is c2: ", '\n',sess.run(c2)
    print "This is d1: ", '\n',sess.run(d1)
    print "This is d2: ", '\n',sess.run(d2)
    print "This is r1: ",  '\n',sess.run(r1)
    print "This is r2: ", '\n',sess.run(r2)
    print "This is r3: ", '\n',sess.run(r3)
    print "This is r4: ", '\n',sess.run(r4)
    print "This is shape of x: ", x.get_shape()

结果:

This is x:  
[[ 0.  0.]
 [ 0.  0.]] 
This is y:  
[[ 1.  1.]
 [ 1.  1.]]
This is z:  
[[3 3]
 [3 3]]
This is c1:  
[1 2 3 4]
This is c2:  
[[-1. -1.]
 [-1. -1.]]
This is d1:  
[ 10.   12.5  15.   17.5  20. ]
This is d2:  
[ 10.  12.  14.  16.  18.]
This is r1:  
[[ 1.69661403  0.64714265  0.61340022  0.13939953]
 [ 1.82771301  0.34095812  0.56674242  0.7125411 ]]
This is r2:  
[[ 0.51340485 -0.25581399  0.65199131]
 [ 1.39236379  0.37256798  0.20336303]]
This is r3:  
[[ 0.51340485 -0.25581399  0.65199131]
 [ 1.39236379  0.1662533  -0.91617972]]
This is r4:  
[[4 5 6]
 [6 6 6]
 [1 2 3]]
This is shape of x:  (2, 2)

截图--->代码



截图-->结果


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汀桦坞

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值