Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Assigning two dimensional array to each other

806067Jan 3 2011 — edited Jan 4 2011
Hi All,
I have two two-dimensional arrays and I want to assign one's second dimension's values as the other's second dimension's values in this way:
        int userCounter = 0;
        for (int userID : mostCommonUsers) {
            reducedTrainingVectorForSimilarity[userCounter] = trainingVectorForSimilarity[userID];
            userCounter++;
        }
In the above code, I have an *"ArrayList<Integer> mostCommonUsers"*, and iterate through this. I'm using the values inside this array list, as a first dimension's index number of the *"trainingVectorForSimilarity"*, and assigning all the values in the second dimension to the left-hand-side array's second dimension. Both array has fixed length of second dimension. So, am I right by doing this, or I should make a for-loop to iterate over the individual values on the second dimensions of both arrays?

Another similar question: In the below code, *"trainingVectorForSimilarity"* is an *"float[][]"*, so basically I assign all the second dimensions' values into a newly created array named *"trainingUserRatings"*. Again, I assumed that if the corresponding first dimesion's second dimension values will be assign without any iteration over each values.
for (int i = 0; i < trainingVectorForSimilarity.length; i++) {
            float[] trainingUserRatings = trainingVectorForSimilarity;
similarity[i] = calculateCosineSimilarity(testingVectorForSimilarity, trainingUserRatings);
}
Am I right for both cases?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2011
Added on Jan 3 2011
18 comments
242 views