就地执行numpy exp函数 [英] Perform numpy exp function in-place
本文介绍了就地执行numpy exp函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就像标题中一样,我需要在非常大的ndarray上执行numpy.exp
,比如说ar
,并将结果存储在ar
本身中.可以就地执行此操作吗?
As in title, I need to perform numpy.exp
on a very large ndarray, let's say ar
, and store the result in ar
itself. Can this operation be performed in-place?
推荐答案
您可以使用exp
的可选out
参数:
You can use the optional out
argument of exp
:
a = np.array([3.4, 5])
res = np.exp(a, a)
print(res is a)
print(a)
输出:
True
[ 29.96410005 148.4131591 ]
exp(x [,out])
exp(x[, out])
计算输入数组中所有元素的指数.
Calculate the exponential of all elements in the input array.
out:ndarray
输出数组,x
的按元素指数.
out : ndarray
Output array, element-wise exponential of x
.
a
的所有元素都将替换为exp
的结果.返回值res
与a
相同.没有创建新的数组
Here all elements of a
will be replaced by the result of exp
. The return value res
is the same as a
. No new array is created
这篇关于就地执行numpy exp函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文