---
title: linalg.tensorsolve
description: "为x求解张量方程a x = b。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0558.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0558.html
indexId: 42450e878dd7524ca3ad16a55d1837eed2e17586bb0afaf8658ab85d7379a4b676
---
# linalg.tensorsolve

#### 功能描述

为x求解张量方程a x = b。

假设x的所有索引都与a的最右边的索引一起求和，例如tensordot(a，x，axes=x.ndim)中所做的那样。


#### 必选输入参数

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| a | array\_like | 系数张量，形状为b.shape+Q。 Q，元组，等于由其最右边索引的适当数量组成的该子张量的形状，并且必须使prod(Q)== prod(b.shape)（在某种意义上说是“正方形”）。 |
| b | array\_like | 右手张量，可以是任何形状。 |


#### 可选输入参数

| 参数名 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| axes | tuple of ints | None | 在求逆之前，在a中向右重新排序的轴。如果值为None，则不会进行重新排序。 |


#### 返回数据

| 类型 | 说明 |
| --- | --- |
| ndarray, shape Q | 张量方程ax = b的解。 |


#### 示例

```
>>> import numpy as np
>>> a = np.eye(2*3*4)
>>> a.shape = (2*3, 4, 2, 3, 4)
>>> b = np.random.randn(2*3, 4)
>>> x = np.linalg.tensorsolve(a, b)
>>> x.shape
(2, 3, 4)
>>>
>>> np.allclose(np.tensordot(a, x, axes=3), b)
True
>>>
```
