tf.ones  的一些用法

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
tf.ones([3, 4], tf.int32)<tf.Tensor: shape=(3, 4), dtype=int32, numpy=
array([[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]], dtype=int32)>def make_variables(k, initializer):
return (tf.Variable(initializer(shape=[k], dtype=tf.float32)),
tf.Variable(initializer(shape=[k, k], dtype=tf.float32)))
v1, v2 = make_variables(3, tf.ones_initializer())v1
Out[41]: <tf.Variable 'Variable:0' shape=(3,) dtype=float32, numpy=array([1., 1., 1.], dtype=float32)>

v2
Out[42]:
<tf.Variable 'Variable:0' shape=(3, 3) dtype=float32, numpy=
array([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]], dtype=float32)>make_variables(4, tf.random_uniform_initializer(minval=-1., maxval=1.))
(<tf.Variable 'Variable:0' shape=(4,) dtype=float32, numpy=array([ 0.9270878 , -0.5173075 , 0.05331755, 0.338547 ], dtype=float32)>,
<tf.Variable 'Variable:0' shape=(4, 4) dtype=float32, numpy=
array([[-0.5852165 , -0.09796047, -0.15223312, 0.9891472 ],
[-0.27840734, 0.2589562 , 0.45455956, -0.8546467 ],
[-0.19497204, -0.4024372 , 0.8427613 , 0.73146725],
[-0.77300024, 0.7703638 , 0.6048634 , -0.15460539]],
dtype=float32)>)tensor = tf.constant([[1, 2, 3], [4, 5, 6]])
tf.ones_like(tensor)<tf.Tensor: shape=(2, 3), dtype=int32, numpy=
array([[1, 1, 1],
[1, 1, 1]], dtype=int32)>x = [1, 2, 3]
y = [4, 5, 6]
X, Y = tf.meshgrid(x, y)


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6