np.log(arr, where=bools) does not return arr[bools] for bools=False
See original GitHub issueHi,
I recently have been debugging a script that takes the log of a 3D image and found that the solution was to circumvent the where argument that you can give the numpy.log function.
This was the orignal code:
print('min',image.min())
print('max', image.max())
image = np.divide(image, image.max())
print('min',image.min())
print('max', image.max())
image = np.log(image, where=image>0)
print('min',image.min())
print('max', image.max())
With the following output:
min 0.0
max 9.1653565625
min 0.0
max 1.0
min -9.86549829948
max 1.0
But when you take the log of a positive number (excluding 0), the answer should always be negative!
The where argument, according to the numpy documentation should do the following:
Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the output alone.
Thus either, the log of some values are wrong or the where argument does not do what the documentation says it should do.
When I started the script with image = image + 0.00001
, it did give the intended behaviour:
min 1e-05
max 9.1653665625
min 1.091063836e-06
max 1.0
min -13.7283573414
max 0.0
This would mean that the where argument does not leave the value alone, but changes it. Since in this case, the values that are changed by log are 0 and the log of 0 is not defined, it is unclear what log should change it to…
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Yes, it wasn’t obvious to me what
where=
does either until I read the documentation. I’m going to reopen your issue: we should at the very least explicitly say that if you providewhere=
but notout=
, the result will have uninitialized memory in the positions markedFalse
bywhere=
.Closing, please reopen if needed.