本文整理汇总了Python中numpy.core.numeric.power方法的典型用法代码示例。如果您正苦于以下问题:Python numeric.power方法的具体用法?Python numeric.power怎么用?Python numeric.power使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.core.numeric
的用法示例。
在下文中一共展示了numeric.power方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: power
# 需要导入模块: from numpy.core import numeric [as 别名]
# 或者: from numpy.core.numeric import power [as 别名]
def power(x, p):
"""
Return x to the power p, (x**p).
If `x` contains negative values, the output is converted to the
complex domain.
Parameters
----------
x : array_like
The input value(s).
p : array_like of ints
The power(s) to which `x` is raised. If `x` contains multiple values,
`p` has to either be a scalar, or contain the same number of values
as `x`. In the latter case, the result is
``x[0]**p[0], x[1]**p[1], ...``.
Returns
-------
out : ndarray or scalar
The result of ``x**p``. If `x` and `p` are scalars, so is `out`,
otherwise an array is returned.
See Also
--------
numpy.power
Examples
--------
>>> np.set_printoptions(precision=4)
>>> np.lib.scimath.power([2, 4], 2)
array([ 4, 16])
>>> np.lib.scimath.power([2, 4], -2)
array([ 0.25 , 0.0625])
>>> np.lib.scimath.power([-2, 4], 2)
array([ 4.+0.j, 16.+0.j])
"""
x = _fix_real_lt_zero(x)
p = _fix_int_lt_zero(p)
return nx.power(x, p)