The ufunc documentation states:
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.
What is the default behavior, when out
is not given?
I observed some behavior, which doesn't really make sense to me:
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
Does anyone know the underlying reason/behavior?
Especially np.reciprocal
doesn't really make sense, as the reciprocal value can never be 0
EDIT: The behavior is even more complex:
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...
I'm using Numpy version 1.11.1
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…