Python Forum
iterate through the dict_values while unpacking the dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iterate through the dict_values while unpacking the dictionary
#1
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.
Reply
#2
NormalizeData does something. You ignore the results. Try using the returned value.
PeacockOpenminded likes this post
Reply
#3
Yes, ignore the results and try to use the value returned.
PeacockOpenminded likes this post
Reply
#4
(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 :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unpacking a dict with * or ** msrk 4 997 Dec-02-2023, 11:50 PM
Last Post: msrk
  accessing value in dict_values class CompleteNewb 14 5,208 Mar-31-2022, 04:02 AM
Last Post: deanhystad
  Unpacking zip object Mark17 12 3,246 Mar-28-2022, 04:59 PM
Last Post: deanhystad
  unpacking list wardancer84 2 1,894 Sep-11-2021, 02:42 PM
Last Post: wardancer84
  unpacking tuple not working project_science 1 1,497 Jan-09-2021, 09:09 PM
Last Post: buran
  Unpacking a list Mark17 3 2,629 Dec-18-2020, 05:08 AM
Last Post: aajkaal
  Unpacking wheel files DavidTheGrockle 3 11,442 Dec-15-2020, 05:11 PM
Last Post: DavidTheGrockle
  Why the result of "extended iterable unpacking" with set() is unpredictable? zohanlin 2 2,078 Jun-29-2020, 10:30 AM
Last Post: zohanlin
  How to iterate dict_values data type nisusavi 2 7,537 Apr-17-2020, 08:06 PM
Last Post: nisusavi
  Unpacking nested lists yonatan776 1 2,214 Apr-14-2020, 08:50 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020