linalg.tensorinv
功能描述
结果是相对于张量点积运算tensordot(a, b, ind)的逆,即在浮点精度下,tensordot(tensorinv(a), a, ind)是张量运算的“单位”张量。
必选输入参数
| 参数名 | 类型 | 说明 | 
|---|---|---|
| a | array_like | “求逆”的张量。它的形状必须是“正方形”,即prod(a.shape[:ind]) == prod(a.shape[ind:])。 | 
可选输入参数
| 参数名 | 类型 | 默认值 | 说明 | 
|---|---|---|---|
| ind | int | 2 | 反向和中涉及的第一个索引的数量。必须是正整数。 | 
返回数据
| 类型 | 说明 | 
|---|---|
| ndarray | a的张量点积的逆,形状为a.shape[ind:] + a.shape[:ind]。 | 
示例
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | >>> import numpy as np >>> a = np.eye(4*6) >>> a.shape = (4, 6, 8, 3) >>> >>> ainv = np.linalg.tensorinv(a, ind=2) >>> ainv.shape (8, 3, 4, 6) >>> >>> b = np.random.randn(4, 6) >>> np.allclose(np.tensordot(ainv,b), np.linalg.tensorsolve(a,b)) True >>> >>> a = np.eye(4*6) >>> a.shape = (24, 8, 3) >>> ainv = np.linalg.tensorinv(a, ind=1) >>> ainv.shape (8, 3, 24) >>> >>> b = np.random.randn(24) >>> np.allclose(np.tensordot(ainv,b,1), np.linalg.tensorsolve(a,b)) True >>> | 
父主题: 线性代数函数