将矩阵 a 乘以向量 b ,产生 a * b 。
用法
tf.linalg.matvec(
a, b, transpose_a=False, adjoint_a=False, a_is_sparse=False, b_is_sparse=False,
name=None
)参数
-
aTensor类型为float16,float32,float64,int32,complex64,complex128且排名 > 1。 -
bTensor与a具有相同的类型和兼容的尺寸。 -
transpose_a如果True,a在乘法之前被转置。 -
adjoint_a如果True,a在乘法之前被共轭和转置。 -
a_is_sparse如果True,a被视为稀疏矩阵。 -
b_is_sparse如果True,b被视为稀疏矩阵。 -
name操作的名称(可选)。
返回
-
A
Tensor同类型的a和b其中每个 inner-most 向量是相应矩阵的乘积a和向量b,例如如果所有转置或伴随属性都是False:output[..., i] = sum_k (a[..., i, k] *b[..., k]),对于所有索引 i。 -
Note这是matrix-vector 产品,而不是元素产品。
抛出
-
ValueError如果 transpose_a 和 adjoint_a 都设置为 True。
矩阵 a 在任何转置之后必须是秩 >= 2 的张量,其中 shape(a)[-1] == shape(b)[-1] 和 shape(a)[:-2] 能够使用 shape(b)[:-1] 进行广播。
a 和b 必须是同一类型。支持的类型是:float16 , float32 , float64 , int32 , complex64 , complex128。
矩阵 a 可以通过将相应标志之一设置为 True 来动态转置或连接(共轭和转置)。默认情况下,这些是False。
如果一个或两个输入包含很多零,则可以通过将相应的 a_is_sparse 或 b_is_sparse 标志设置为 True 来使用更有效的乘法算法。默认情况下,这些是False。此优化仅适用于数据类型为 bfloat16 或 float32 的普通矩阵/向量(rank-2/1 张量)。
例如:
# 2-D tensor `a`
# [[1, 2, 3],
# [4, 5, 6]]
a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3])
# 1-D tensor `b`
# [7, 9, 11]
b = tf.constant([7, 9, 11], shape=[3])
# `a` * `b`
# [ 58, 64]
c = tf.linalg.matvec(a, b)
# 3-D tensor `a`
# [[[ 1, 2, 3],
# [ 4, 5, 6]],
# [[ 7, 8, 9],
# [10, 11, 12]]]
a = tf.constant(np.arange(1, 13, dtype=np.int32),
shape=[2, 2, 3])
# 2-D tensor `b`
# [[13, 14, 15],
# [16, 17, 18]]
b = tf.constant(np.arange(13, 19, dtype=np.int32),
shape=[2, 3])
# `a` * `b`
# [[ 86, 212],
# [410, 563]]
c = tf.linalg.matvec(a, b)
相关用法
- Python tf.linalg.matrix_transpose用法及代码示例
- Python tf.linalg.matmul用法及代码示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代码示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代码示例
- Python tf.linalg.LinearOperatorIdentity.solvevec用法及代码示例
- Python tf.linalg.LinearOperatorPermutation.solve用法及代码示例
- Python tf.linalg.band_part用法及代码示例
- Python tf.linalg.LinearOperatorKronecker.diag_part用法及代码示例
- Python tf.linalg.lu_matrix_inverse用法及代码示例
- Python tf.linalg.LinearOperatorToeplitz.matvec用法及代码示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.solvevec用法及代码示例
- Python tf.linalg.LinearOperatorLowerTriangular.matvec用法及代码示例
- Python tf.linalg.LinearOperatorCirculant2D.solve用法及代码示例
- Python tf.linalg.LinearOperatorCirculant3D.diag_part用法及代码示例
- Python tf.linalg.LinearOperatorToeplitz.solvevec用法及代码示例
- Python tf.linalg.LinearOperatorCirculant2D.assert_non_singular用法及代码示例
- Python tf.linalg.LinearOperatorPermutation.diag_part用法及代码示例
- Python tf.linalg.LinearOperatorToeplitz用法及代码示例
- Python tf.linalg.LinearOperatorCirculant2D.matvec用法及代码示例
- Python tf.linalg.LinearOperatorTridiag.solvevec用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.linalg.matvec。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
