numpy np.power()函数(多维幂运算)

from numpy\core\umath.py

def power(x1, x2, *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ 
    """
    power(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
    
    First array elements raised to powers from second array, element-wise.
    第一个数组元素按元素从第二个数组提升为幂。
    
    Raise each base in `x1` to the positionally-corresponding power in
    `x2`.  `x1` and `x2` must be broadcastable to the same shape. Note that an
    integer type raised to a negative integer power will raise a ValueError.

	将“ x1”中的每个基数提高到“ x2”中的位置对应的幂。 x1和x2必须可广播为相同形状。 
	请注意,将整数类型提高为负整数次幂将引发ValueError。
    
    Parameters
    ----------
    x1 : array_like
        The bases. 基底
    x2 : array_like
        The exponents. 指数
    out : ndarray, None, or tuple of ndarray and None, optional
        A location into which the result is stored. If provided, it must have
        a shape that the inputs broadcast to. If not provided or `None`,
        a freshly-allocated array is returned. A tuple (possible only as a
        keyword argument) must have length equal to the number of outputs.
        结果存储的位置。 如果提供,它必须具有输入广播到的形状。 
        如果未提供或没有,则返回一个新分配的数组。 
        元组(只能作为关键字参数)的长度必须等于输出的数量。
    where : array_like, optional
        Values of True indicate to calculate the ufunc at that position, values
        of False indicate to leave the value in the output alone.
        值为True表示要在该位置计算ufunc,值为False表示将值保留在输出中。
    **kwargs
        For other keyword-only arguments, see the
        :ref:`ufunc docs <ufuncs.kwargs>`.
    
    Returns
    -------
    y : ndarray
        The bases in `x1` raised to the exponents in `x2`.
        This is a scalar if both `x1` and `x2` are scalars.
        x1中的基数上升到x2中的指数。
         如果x1和x2均为标量,则为标量。
    
    See Also
    --------
    float_power : power function that promotes integers to float
    提升整数浮点数的幂函数
    
    Examples
    --------
    Cube each element in a list.
    对列表中的每个元素进行多维数据集处理。
    
    >>> x1 = range(6)
    >>> x1
    [0, 1, 2, 3, 4, 5]
    >>> np.power(x1, 3)
    array([  0,   1,   8,  27,  64, 125])
    
    Raise the bases to different exponents.
    将底数提高到不同的指数。
    
    >>> x2 = [1.0, 2.0, 3.0, 3.0, 2.0, 1.0]
    >>> np.power(x1, x2)
    array([  0.,   1.,   8.,  27.,  16.,   5.])
    
    The effect of broadcasting.
    广播的效果。
    
    >>> x2 = np.array([[1, 2, 3, 3, 2, 1], [1, 2, 3, 3, 2, 1]])
    >>> x2
    array([[1, 2, 3, 3, 2, 1],
           [1, 2, 3, 3, 2, 1]])
    >>> np.power(x1, x2)
    array([[ 0,  1,  8, 27, 16,  5],
           [ 0,  1,  8, 27, 16,  5]])
    """
    pass
发布了747 篇原创文章 · 获赞 28 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/Dontla/article/details/103958721