---
title: power
description: "将第一个输入中的每个元素作为底数，第二个输入中的每个元素作为指数，计算其结果，即。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_1095.html
sourcePath: /source/zh/kunpenghpcs/hpckit/devg/kunpengaccel_kml_1095.html
indexId: 62c4ba35d34b7c902434fd53be6ad525bdd8f725c37ce9f3cbd6a4f3acf0e5a561
---
# power

#### 功能描述

将第一个输入中的每个元素作为底数，第二个输入中的每个元素作为指数，计算其结果，即。

x1和x2必须能广播至相同的形状。若x1[i]为整数且x2[i]为负整数，则会抛出ValueError异常。若x1[i]<0且x2[i]不是整数，则返回nan。返回复数结果需要将输入的数据类型转换为complex或者指定dtype=complex。


#### 必选输入参数

| 参数名 | 类型 | 说明 |
| --- | --- | --- |
| x1 | array\_like | 底数，输入的数组或标量。 |
| x2 | array\_like | 指数，输入的数组或标量。若x1.shape!=x2.shape，则它们必须能广播至相同形状。 |


#### 可选输入参数

| 参数名 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| out | ndarray或ndarray的元组 | None | 计算结果保存的位置。如果提供，其形状必须与输入数组广播后的形状一致。未指定时，返回一个新的数组。 |
| where | array\_like | None | 将被广播至输入的条件数组。在条件为真处的元素，其计算结果会存入out中，其余位置保留原有值。 |
| \*\*kwargs | \- | \- | 其他关键字参数，请参见NumPy官方文档Universal functions (ufunc)(https://numpy.org/doc/stable/reference/ufuncs.html\#ufuncs\-kwargs)。 |


#### 返回数据

| 类型 | 说明 |
| --- | --- |
| ndarray/scalar | 幂运算的结果。 |


#### 示例

```
>>> import numpy as np
>>> np.power(3, 2)
9
>>> x1 = np.arange(6)
>>> x1
array([0, 1, 2, 3, 4, 5])
>>> np.power(x1, 3)
array([  0,   1,   8,  27,  64, 125])
>>> 
>>> x2 = [1.0, 2.0, 3.0, 3.0, 2.0, 1.0]
>>> np.power(x1, x2)
array([ 0.,  1.,  8., 27., 16.,  5.])
>>>
```
