理解numpy.power

这篇博客详细介绍了NumPy库中的numpy.power函数,该函数用于进行元素级的指数运算。它接受两个数组x1和x2作为参数,分别作为基数和指数,返回的结果是x1的x2次方。当数组形状不同时,它们会被广播到相同的形状。需要注意的是,如果整数类型的数据被赋予负整数幂,会引发ValueError。博客还提到了函数的其他可选参数如out、where等,以及返回值的类型和形状。
  • numpy.power

    numpy.power(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])=<ufunc 'power'>

    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.

  • Parameters

    paratypemeaning
    x1array_likethe bases
    x2array_likethe exponents.
    If x1.shape!=x2.shape, they must be broadcastable to a common shape(which becomes the shape of the output)
    outndarray,None, or tuple of ndarray and None, optionalA location into which the result is stored.
    wherearray_like, optional
    **kwargsOptional keyword arguments

    Returns y which is ndarray. The bases in x1 raised to the exponent in x2. It is a scalar if both x1 and x2 are scalars.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值