From 3a774bc18268899026c6c2097011212c770f67f8 Mon Sep 17 00:00:00 2001 From: Michael Shay Date: Sun, 5 Sep 2021 11:19:18 -0600 Subject: [PATCH] Fixed function findval to allow for multiple "closest" values. --- py3d/sub.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/py3d/sub.py b/py3d/sub.py index 83fd42a..abbb28c 100755 --- a/py3d/sub.py +++ b/py3d/sub.py @@ -1208,8 +1208,8 @@ def sim_movies(**mvargs): def findval(vec,val): """Returns index value of 1D array vec which is closest to scalar val - WARNING: 8/27/2021: Currently this function assumes that vec is monotonically increasing or - decreasing. If it isn't, it may return an array. + WARNING: 9/5/2021: If multiple values of array vec are equidistant from scalar + val, the value with the lowest index is returned. Args: @@ -1219,6 +1219,6 @@ def findval(vec,val): """ vec2 = abs( (vec - val)**2 ) - index = ( np.where(vec2 == vec2.min()))[0].item() + index = ( np.where(vec2 == vec2.min()))[0][0] return index #======================================================