TensorFlow2.0中矩阵和向量加减乘操作的具体实例有哪些?

2026-06-10 00:260阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计259个文字,预计阅读时间需要2分钟。

TensorFlow2.0中矩阵和向量加减乘操作的具体实例有哪些?

1. 使用numpy生成随机矩阵a和随机整数矩阵b:pythona=np.random.random((3, 3))b=np.random.randint(0, 9, (3, 3))

2. 使用TensorFlow的加法运算符计算矩阵a和b的和:pythonad=tf.add(a, b)

3. 注意矩阵乘法运算:python注意:此处未展示矩阵乘法,仅提醒需注意

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())

自动化学习。

阅读全文
标签:加减

本文共计259个文字,预计阅读时间需要2分钟。

TensorFlow2.0中矩阵和向量加减乘操作的具体实例有哪些?

1. 使用numpy生成随机矩阵a和随机整数矩阵b:pythona=np.random.random((3, 3))b=np.random.randint(0, 9, (3, 3))

2. 使用TensorFlow的加法运算符计算矩阵a和b的和:pythonad=tf.add(a, b)

3. 注意矩阵乘法运算:python注意:此处未展示矩阵乘法,仅提醒需注意

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())

自动化学习。

阅读全文
标签:加减