小编Ham*_*mza的帖子

如何将向量的每个元素提升为另一个向量的每个元素的幂?

我想通过从 0 到 5 的递增幂来提高向量:

import numpy as np

a = np.array([1, 2, 3]) # list of 11 components
b = np.array([0, 1, 2, 3, 4]) # power
c = np.power(a,b)
Run Code Online (Sandbox Code Playgroud)

期望的结果是:

c = [[1**0, 1**1, 1**2, 1**3, 1**4], [2**0, 2**1, ...], ...]
Run Code Online (Sandbox Code Playgroud)

我不断收到此错误:

ValueError: operands could not be broadcast together with shapes (3,) (5,)
Run Code Online (Sandbox Code Playgroud)

python numpy array-broadcasting

5
推荐指数
2
解决办法
163
查看次数

标签 统计

array-broadcasting ×1

numpy ×1

python ×1