np.random.normal()给出均值为loc,标准差为scale的高斯随机数(场).
numpy.random.normal(loc=0.0, scale=1.0, size=None)
a=np.random.normal(0,1,(2,1))
b=np.random.normal(0,1,(1,2))
c=np.random.normal(0,1,(2))
print(a)
print(a.shape)
print(b)
print(b.shape)
print(c)
print(c.shape)
[[ 1.11843359]
[-0.69801129]]
(2, 1)
[[-0.87110089 -0.46089345]]
(1, 2)
[ 0.88227522 -0.26728542]
(2,)
theano.shared可以看作是将变量设置为全局变量,其值可以在多个函数中共用.
1. 通过get_value()、set_value()可以查看、设置共享变量的数值;
import numpy, theano
np_array = numpy.ones(2, dtype='float32')
s_default = theano.shared(np_array)
print s_default
print s_default.get_value()
s_default.set_value([5., 5.])
print s_default.get_value()
输出:
<TensorType(float32, vector)>
[ 1. 1.]
[ 5. 5.]
2. 参数name:用于在关键字参数中用于标识此参数的字符串;
import numpy, theano
np_array = numpy.ones(2, dtype='float32')
s_default = theano.shared(np_array, name='s_default')
print 's_default.name:',s_default.name
输出:
s_default.name: s_default
3. 参数borrow:borrow=True/False:对数据的任何改变会/不会影响到原始的变量;
import numpy, theano
np_array = numpy.ones(2, dtype='float32')
s_default = theano.shared(np_array)
s_false = theano.shared(np_array, borrow=False)
s_true = theano.shared(np_array, borrow=True)
np_array += 1
print 's_default:',s_default.get_value()
print 's_false:',s_false.get_value()
print 's_true:',s_true.get_value()
输出:
s_default: [ 1. 1.]
s_false: [ 1. 1.]
s_true: [ 2. 2.]