where
New in version 1.7. Accepts a boolean array which is broadcast together with the operands. Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the output alone.
当out
未给定时,默认行为是什么?你知道吗
我观察到一些行为,这对我来说真的没有意义:
import numpy as np
a,b = np.ones((2,2))
np.add(a,b,where = False) #returns 0
np.exp(a, where = False) #returns 1
np.sin(a, where = False) #returns 1
np.sign(a, where = False) #returns 0
np.reciprocal(a, where = False) #returns 0
有人知道潜在的原因/行为吗?
尤其是np.reciprocal
实际上没有意义,因为倒数永远不能是0
编辑:行为更为复杂:
a,b = np.ones(2)
np.add(a,b,where = False) #returns 6.0775647498958414e-316
a,b = 1,1
np.add(a,b, where = False) #returns 12301129,
#running this line several times doesn't give the same result every time...
我使用的是Numpy版本1.11.1
它看起来像垃圾,因为它就是被垃圾收集的内存。你知道吗
无论调用什么函数,都会留出一块内存来放入结果,但决不会将任何结果放入其中,因为
where=False
。您得到的值与从np.empty
得到的值相同,也就是说,在函数赋值之前,内存块中有任何垃圾。你知道吗相关问题 更多 >
编程相关推荐