6

I have two vectors. I would like a "cross product"-esque function that will take each value from the first vector and raise it to the exponent of each value in a second vector, returning a matrix. Is there anything built in to numpy that does this? It could be done with loops but I'm looking for something efficient.

For example:

>>> cross_exp([1,2], [3,4]) 
[[1, 1],[8, 16]]
4

1 回答 1

8

听起来您可能想要np.power.outer

>>> np.power.outer([1,2], [3,4])
array([[ 1,  1],
       [ 8, 16]])

大多数 ufunc 都有一个outer方法,可以计算来自两个数组的所有值对的运算结果(注意这与叉积不同)。

于 2015-09-16T15:08:41.033 回答