网络编程
位置:首页>> 网络编程>> Python编程>> TensorFlow2.0矩阵与向量的加减乘实例

TensorFlow2.0矩阵与向量的加减乘实例

作者:缘高情定  发布时间:2023-12-30 13:21:00 

标签:TensorFlow2.0,矩阵,向量,加减乘

1、矩阵加法使用


a = np.random.random((3,3))
b = np.random.randint(0,9,(3,3))
ad = tf.add(a,b)

2、矩阵乘法注意


# tensorflow 使用矩阵乘法都必须使用相同类型的数据,否则报错。
a = np.random.random((5,3))
b = np.random.randint(0,9,(3,6))
c = tf.tensordot(a.astype(np.float),b.astype(np.float),axes=1)
print(c.numpy())

3、矩阵减法


a = np.random.random((3,3))
b = np.random.randint(0,9,(3,3))
ad = tf.subtract(a,b)

4、数的除法


d = tf.divide(9*2,3)
print(d.numpy())

自动化学习。

来源:https://www.cnblogs.com/wuzaipei/p/10956118.html

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com