iterate through the dict_values while unpacking the dictionary - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: iterate through the dict_values while unpacking the dictionary (/thread-39241.html) |
iterate through the dict_values while unpacking the dictionary - PeacockOpenminded - Jan-19-2023 I have trouble with iterating through dict_values, while unpacking the dictionary. I have a dictionary which contains 2 arrays, a and b: a = np.array([[3, 1, 3, 2], [1, 3, 3, 1], [1, 1, 3, 1], [1, 2, 2, 3]]) b = np.array([[1, 2, 4, 3], [1, 3, 4, 3], [2, 4, 4, 2], [2, 2, 2, 4]]) dic = {"arr1": a, "arr2": b}I want to scale the values of a and b on a scale of 0 to 1 range. I wrote a function for that and want to iterate it over the arrays, and at the end, I want to get the dictionary including the arrays with values between 0 to 1. def NormalizeData(i): return (i - np.nanmin(i)) / (np.nanmax(i) - np.nanmin(i)) for i in dic.values(): NormalizeData(i) print(i)but this function (NormalizeData) doesn't do anything. I'd appreciate for any suggestions why my current code does not work. RE: iterate through the dict_values while unpacking the dictionary - deanhystad - Jan-19-2023 NormalizeData does something. You ignore the results. Try using the returned value. RE: iterate through the dict_values while unpacking the dictionary - prvncpa - Jan-19-2023 Yes, ignore the results and try to use the value returned. RE: iterate through the dict_values while unpacking the dictionary - PeacockOpenminded - Jan-22-2023 (Jan-19-2023, 01:36 PM)deanhystad Wrote: NormalizeData does something. You ignore the results. Try using the returned value. Yes it indeed did something! thank you so much for pointing it out. (Jan-19-2023, 01:36 PM)deanhystad Wrote: NormalizeData does something. You ignore the results. Try using the returned value. Thank you! problem solved :) (Jan-19-2023, 01:59 PM)prvncpa Wrote: Yes, ignore the results and try to use the value returned. Thank you! problem solved :) |