Computing the average values in an array based on the duplicate values in another array
Hi I have 2 arrays, one int array and one float array. And I would like to detect duplicate values that are not zeros in the int array.
int numbers = [4, 3, 3, 3, 2, 2, 1, 0, 0, 0]
Here, we can see that there are three 3's and two 2's.
float rates = [0.16f, 0.12f, 0.10f, 0.09f, 0.08f, 0.07f, 0.06f, 0.02f, 0.02f, 0.02f]
btw, the int and float array are always sorted in descending order
the result I want is : (int and float array are always 10 in size)
float rates = [0.16f, 0.1033333333333333f, 0.1033333333333333f, 0.1033333333333333f, 0.075f, 0.075f, 0.06f, 0.02f, 0.02f, 0.02f]**
getting the positions of the same value in the int array, and calculate the average values on the float array. Ignoring the zero values (0.02 + 0.02 + 0.02 = 0.06 / 3 is also 0.02 to each of them but it's better if the game do not compute for this)
How do I do this?
Your answer
![](https://koobas.hobune.stream/wayback/20220612093541im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Array with pushing values? 0 Answers
How to get variable by name(string typed in inspector) in array with index from another script? 0 Answers
Class array initialization on Start() gives -> Object reference not set to an instance of an object 1 Answer
Index out of range error 1 Answer
least 'expensive' way to go through list and check transform.position 0 Answers