---
title: matmul
description: "两个数组的矩阵乘积。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0543.html
sourcePath: /source/zh/kunpengboostkithistory/240RC2/accel/kunpengaccel_kml_16_0543.html
indexId: 7dbe36779bb505e3f9873c2c77f6032c0ab67584ab6b8d67d665ebdd09253fdb76
---
# matmul

#### 功能描述

两个数组的矩阵乘积。


#### 必选输入参数

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| x1 | array\_like | 第一个实参。 |
| x2 | array\_like | 第二个实参。 |


注意，不允许输入标量，否则抛出异常。


#### 可选输入参数

| 参数名 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| out | ndarray | None | 存储结果的位置。如果提供，它必须具有与签名(n,k),(k,m)\->(n,m)匹配的形状。如果没有提供或None，则返回新分配的数组。 |
| \*\*kwargs | \- | \- | 其他关键字参数，见NumPy的ufunc相关文档(https://numpy.org/doc/stable/reference/ufuncs.html\#ufuncs\-kwargs)。 |


#### 返回数据

| 类型 | 说明 |
| --- | --- |
| ndarray | 输入的矩阵乘积。只有当x1、x2都是一维向量时，这才是一个标量。 |


#### 示例

```
>>> import numpy as np
>>> a = np.array([1,2,3])
>>> b = np.array([0,1,2])
>>> np.inner(a, b)
8
>>>
>>> a = np.arange(24).reshape((2,3,4))
>>> a
array([[[ 0,  1,  2,  3],
[ 4,  5,  6,  7],
[ 8,  9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
>>> b = np.arange(4)
>>> b
array([0, 1, 2, 3])
>>> np.inner(a, b)
array([[ 14,  38,  62],
[ 86, 110, 134]])
>>>
>>> a = np.arange(2).reshape((1,1,2))
>>> b = np.arange(6).reshape((3,2))
>>> np.inner(a, b)
array([[[1, 3, 5]]])
>>>
>>> a = np.eye(2)
>>> a
array([[1., 0.],
[0., 1.]])
>>> np.inner(a, 5)
array([[5., 0.],
[0., 5.]])
>>>
```
