Re: Matrix Rotation in Python?

2020-07-17 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: Matrix Rotation in Python?

Extracted raw image data typically comes in byte string format, and each pixel value comes as 4 bytes representing Red, Green, Blue, and Alpha offsets, though not always or with all formats. Usually when handling that kind of data I use an NxN matrix with 4 elements per index, numpy would also make the kind of necessary transformations rather trivial, though that may not be the point of the current exercise.Running the code it seems to flip it horizontally rather than rotate it by 90 degree's, although this may depend on matrix and data formatting. A different approach may be to read each horizontal column of the original array, and append each element to the vertical column of the current or new array.

URL: https://forum.audiogames.net/post/553391/#p553391




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Matrix Rotation in Python?

2020-07-17 Thread AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector


  


Re: Matrix Rotation in Python?

Extracted raw image data typically comes in byte string format, and each pixel value comes as 4 bytes representing Red, Green, Blue, and Alpha offsets, though not always or with all formats. Usually when handling that kind of data I use an NxN matrix with 4 elements per index, numpy would also make the kind of necessary transformations rather trivial, though that may not be the point of the current exercise.Running the code it seems to flip it horizontally rather than rotate it by 90 degree's, although this may depend on matrix and data formatting. With a rotation you may want to populate a new array with elements from the original, because otherwise you may be overwriting existing elements of the data as you transform it. A different approach may be to read each horizontal column of the original array, and append each element to the vertical column of a new array.

URL: https://forum.audiogames.net/post/553391/#p553391




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Matrix Rotation in Python?

2020-07-17 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Matrix Rotation in Python?

Ah, I see. My bad for misunderstanding.

URL: https://forum.audiogames.net/post/553381/#p553381




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Matrix Rotation in Python?

2020-07-17 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: Matrix Rotation in Python?

I'm not saying use numpy to do it. I'm saying, primarily, use numpy to get good known data to compare against.

URL: https://forum.audiogames.net/post/553369/#p553369




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Matrix Rotation in Python?

2020-07-17 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Re: Matrix Rotation in Python?

I see. Thank you. I will look into this some more, though the objective was to write it by hand and not use existing libraries.   Appreciate the explanation.

URL: https://forum.audiogames.net/post/553364/#p553364




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: Matrix Rotation in Python?

2020-07-17 Thread AudioGames . net Forum — Developers room : camlorn via Audiogames-reflector


  


Re: Matrix Rotation in Python?

The 4 bytes long part of the question means that the exercise expects you to get it as a string of binary data, and that the size of the elements in the array of binary data is 4 bytes.  Think of it like C.I think your implementation is correct and it would be the most efficient in C, but, for what it's worth, you can do 90 degree shifts with a matrix transpose and a flip around the x and/or y axis.  If you did that with numpy, you could fill random array sizes with random data, then compare the two implementations together.  Bonus points if you figure out how to use a library called hypothesis with that to test it, but that's also known as massive overkill, even if it is a somewhat good hypothesis learning example.

URL: https://forum.audiogames.net/post/553361/#p553361




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Matrix Rotation in Python?

2020-07-17 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Matrix Rotation in Python?

So I got the following problem:Given an image represented by an NxN matrix, where each pixel in the image is 4bytes, write a method to rotate the image by 90 degrees. The problem did not show sample input, so I had to infer some things, mainly the parameters. After a bit, I had the following:def rotate(matrix):
rows = len(matrix)
columns = len(matrix[0])
for row in range(rows):
for column in range(columns // 2):
matrix[row][columns - 1 - column], matrix[row][column] = matrix[row][column], matrix[row][columns - 1 - column]
return matrixMy question is, does this implementation look correct? I receive the correct output when running some tests, but that doesn't really clarify the problem. Am I missing a piece of information from the question? I am asking because I did not use the "4 bytes long" piece of part of the exercise, which makes me concerned that I misunderstood the problem.Clarifications are greatly appreciated

URL: https://forum.audiogames.net/post/553358/#p553358




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Matrix Rotation in Python?

2020-07-17 Thread AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector


  


Matrix Rotation in Python?

So I got the following problem:Given an image represented by an NxN matrix, where each pixel in the image is 4bytes, write a method to rotate the image by 90 degrees. The problem did not show sample input, so I had to infer some things, mainly the parameters. After a bit, I had the following:def rotate(matrix):
rows = len(matrix)
columns = len(matrix[0])
for row in range(rows):
for column in range(columns // 2):
matrix[row][columns - 1 - column], matrix[row][column] = matrix[row][column], matrix[row][columns - 1 - column]
return matrixMy question is, does this implementation look correct? Am I missing a piece of information from the problem? I am asking because I did not use the "4 bytes long" piece of part of the exercise, which makes me concerned that I misunderstood the problem.Clarifications are greatly appreciated

URL: https://forum.audiogames.net/post/553358/#p553358




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector