tensorflow函数
cc 提升ing 变优秀ing
有需要搜广推nlp实习生的部门吗?
展开
-
tensorflow的reshape(1,-1)和reshape(-1,1)
变成一维列向量y_train = y_data.reshape(-1, 1)变成一维行向量y_train = y_data.reshape(1, -1)原创 2020-09-27 22:00:03 · 894 阅读 · 0 评论 -
tensorflow常用函数:随机数生成:random.RandomState
1.生成【0.1)之间的随机数:2.另一种用法:类似crdm = np.random.RandomState(seed=1)a = rdm.rand()b = rdm.rand(2, 3)print("a:", a)print("b:", b)原创 2020-04-18 10:56:39 · 483 阅读 · 0 评论 -
tensorflow常用函数:tf.data.Dataset.from_tensor_slices
代码:tf.data.Dataset.from_tensor_slices((x_train, y_train)).batch(32)作用:将标签和特征值进行配对,然后每一打32个进行打包。原创 2020-04-17 20:24:06 · 1566 阅读 · 0 评论 -
tensorflow常用函数:np.random.shuffle
代码:np.random.shuffle(x_data)x_data是一个张量,该函数用于将x——data自身打乱,注意是在原数组上进行的,不是返回一个新数组,而原张量不变。原创 2020-04-17 17:20:55 · 1113 阅读 · 0 评论 -
tensorflow常用函数:matmul:对两个矩阵做乘法运算。
代码:a = tf.ones([3, 2])b = tf.fill([2, 3], 3.)print("a:", a)print("b:", b)print("a*b:", tf.matmul(a, b))原创 2020-04-17 16:40:05 · 556 阅读 · 0 评论 -
tensorflow常用函数: tf.convert_to_tensor:将类型转化为tensor的数据类型
代码:将numpy格式的转化为tensor格式的。a = np.arange(0, 5)# 把numpy格式的转化为tensor的数据类型b = tf.convert_to_tensor(a, dtype=tf.int64)print("a:", a)print("b:", b)结果:...原创 2020-04-17 12:03:09 · 2915 阅读 · 0 评论 -
TensorFlow常用函数:用loss对指定结构求参数:GradientTape(),gradient()
一般使用with结构:为固定结构with tf.GradientTape() as tape: # with结构到grads框起了梯度的计算过程。 loss = tf.square(w + 1) # 定义损失函数为w+1的平方grads = tape.gradient(loss, w) # .gradient函数告知谁对谁求导loss定义损失函数是什么,gradient(lo...原创 2020-04-17 11:45:59 · 856 阅读 · 0 评论 -
tensorflow常用函数:tf.Variable:变量,相当于把变量标记为了可训练的。
tf.Variable:w_1 = tf.Variable(3,name="w_1")或者不写变量名:w_1 = tf.Variable(3)或参考:https://blog.csdn.net/u012436149/article/details/53696970?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogC...原创 2020-04-17 11:36:45 · 572 阅读 · 0 评论 -
TensorFlow常用函数:创建张量(tf.constant),及一些特殊张量的创建。zeros,ones,fill,正态分布:random.normal和random.truncated_norm
创建常量(tf.constant)函数原型:tf.constant( value, dtype=None, shape=None, name='Const', verify_shape=False)第一个参数是值,可以是单个的数,也可以是一个列表。第二个参数是创建的变量的类型。默认是intt=tf.constant([1,2])如上创建出,显...原创 2020-04-17 11:29:02 · 408 阅读 · 0 评论