生成随机数语法速查

import tensorflow as tf

w1=tf.Variable(tf.random_uniform([2,2],-1,1))

with tf.Session() as sess:
    init = tf.global_variables_initializer()
    sess.run(init)
    print(sess.run(w1))

输出得

[[ 0.94702697 -0.19546461]
 [-0.69034481 -0.10538507]]

n_features=7

w2=tf.Variable(tf.random_normal((n_features,1),mean=0.0,stddev=1.0),name='weights')

with tf.Session() as sess:
    init = tf.global_variables_initializer()
    sess.run(init)
    print(sess.run(w2))

输出:

[[-0.6331901 ]
 [ 2.41542029]
 [-0.83030796]
 [-1.55228913]
 [-0.98885322]
 [-0.63248575]
 [ 0.26187277]]

def feature_normalize(data):
    mu = np.mean(data,axis=0)
    std = np.std(data,axis=0)
    return (data - mu)/std

其中,np.std()的运算为

std = sqrt(mean(abs(x - x.mean())**2))

如果没有指定axis,则是全部元素计算。

注意这里涉及的向量运算是基于每个元素的运算。

std是标准差不是方差。


import numpy as np
ind = np.random.permutation(20)
print(ind)

输出

[11 15  4  1  6 12  8 17 18 14  9  5  7  0 13 10 19  3 16  2]

import numpy as np
import matplotlib.pyplot as plt
s = np.random.poisson(5)
print(s)

s2 = np.random.poisson(5, 10000)
count, bins, ignored = plt.hist(s2, 14, density=True)
plt.show()

输出:4


import numpy as np
mask=np.random.randint(3, size=(256, 256))

生成256×256整数标签<3。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

飞行codes

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

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

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

打赏作者

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

抵扣说明:

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

余额充值