![]() |
| ||
| ordering arrays i have an array weights[16][60] this being 16 rows of 60 elements in each one i have another error[16] which co incides with each with the 16 rows, this is the error from each row. is there a way i can put each of the 16 in order in the array and then mimic that into the weights array so that all of those are like the ones in the error array? |
| ||
| Re: ordering arrays I'm afraid I'm not getting what you're trying to say. Maybe it's too late for this... :-) Are you trying to put the content of one array into the other or am I getting you wrong? Please elaborate |
| ||
| Re: ordering arrays You want to sort the error array and keep the relationship with the rows in weights array ??? One way is to use another array that contains indices into both error and weights array. When you sort error array actually move the rows in this third array. Use the third array as indirect access to the other arrays. indices[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};Now to reference weights: assume variable X is an integer that contains the value from errors index weights[ indices[x] ][0]; Or, if that is a little too complex for you, just sort both errors and weights array at the same time. When you exchange elements of errors array also exchange all columns in the corresponding rows of weights. |
| ||
| Re: ordering arrays Quote:
maybe another way to do this is keeping an ID of every array row. And while you order one array, locate the ID in the other and move that one too. Or compare the IDs after the ordering is done, and move them according to that. You'll need to add an extra dimension to your array for that though... Hope this helps :) |
| ||
| Re: ordering arrays sorry i have been looking at code solid for the last few days so my brain is wasted! right the 16 rows in the weights array all have a fitness rating or error, which is stored in the array error here is the code for(int i = 0; i < 16; i++) basically there will be 16 numbers in the array known as error, and i need a way of putting them into order of lowest to highest based on the error. if it helps im training a neural network to recognise 3 patterns using a genetic algorithm, so the part im on right now is sorting out the best half of the strings ( or the best half of the 16 in the array weights) so i can pair them up, swap elements around and create another 8 strings to replace the weakest half of the set. which i will need help with too! |
| ||
| Re: ordering arrays Quote:
|
| ||
| Re: ordering arrays indices is used to indirectly reference the elements of the other two arrays. IMO the best way to understand the concept is to write a small program and test it out. Sort the array then print out the values of the errors array. // assume array has been sorted per my previous post |
| ||
| Re: ordering arrays I think I understand your first post now and the logic would go something like this. I have a multidimensional array of 16 rows and 60 columns per row called 'weights'.Something like that If you need more help say so and I'll try to help if I can. Good luck |
| ||
| Re: ordering arrays cheers that helps a bit, basically what your doing is calling one of the elements in error the lowest until something else comes along which is lower, so basically adding on a number to each one thats lower and adding one for each thats bigger kind of thing? i was thinking of adding a few more dimensions to the arrays with error i would add another dimension which would put a number 0 to 15 along side the error depending on the position it comes i already have 0 to 15 as row numbers, i could add another dimension to keep new position in, which would co inside with the error arrays new number order. but apart from that making it easy for me to read i need to be able to swap them all around puting 0 (or number1) at the top and the worst at the bottom. i take it i would need a temporary place to store the file being moved until a place in the array has become available? i kind of know the logic towards it, its just trying to put into code in a way i understand it is the hard part :( |
| ||
| Re: ordering arrays Do you want to go from the first part of this image to the second part? Assuming in the first part the values are in a random order and blocks of the same color represent linked data. http://img300.imageshack.us/my.php?image=errorjm8.jpg What you do is, again, assume the very first is the lowest and then compare the element of that index to every single other element of the array, in this case 'error' and if there's a lowest value you switch values using an auxiliary variable, yes. In addition to that right after doing that switch and before doing the next comparison you switch the values of all your columns for the 2 rows in 'weights' involved. But, you keep comparing the element of the same index until you've reach the end. And you do this for all elements of 'error'. So if you first compare element in error of index 0 with index 1, you then compare index 0 with index 2 and even if index 2 is lowest and you do the switch the next comparison will be index 0 and index 3 followed by index 0 and index 4. If 'error' were to have only 5 rows, you would stop the comparisons with index 0. the next comparison would be index 1 and index 2, and so on. The last comparison will have to be index 3 and index 4. I hope this helps. |
| All times are GMT -4. The time now is 8:09 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC