I have a problem with replacement elements in a matrix. I have a matrix 3×3 in .txt file. I need to replaceme matrix elements like this : the last element should be first, and the penultimate should be second,…etc. Any ideas?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Remember: You can ALWAYS project higher dimensional data onto lower dimensional data ! Once you realize this, you can easily use the algorithm for reversing a 1D array to reverse a 2D array.
The steps :
1) Convert the 2D array to a 1D array.
2) Reverse the 1D array
3) Write the 1D array reversed contents to a new 2D array.
Although this is overkill for a simple 3×3 case, it easily scales to support more complex
array types.
IMPLEMENTATION :
This is relatively simple. Any 2D matrix can be expressed as a 1D matrix, by simply
indexing and mapping the array indices. For example :
Can be expressed as
So , you must write a mapping from the 2D array to the 1D array, and you will have to write a method like this :