+ 2

[Solved] How to rotate arrays in python?

Array: [ [ 0 1 2 ] [ 3 4 5 ] ] I want this array to be: [ [ 0 3 ] [ 1 4 ] [ 2 5 ] ] It is possible using for loop but that won't be a true numpy coding.

22nd May 2020, 6:34 AM
Lerninn
17 Respostas
22nd May 2020, 8:44 AM
Oma Falk
Oma Falk - avatar
+ 3
Arrray2= zip(*Array) but I would propose numpy indeed.
22nd May 2020, 6:44 AM
Oma Falk
Oma Falk - avatar
+ 3
Find the word ANNA in this matrix AXXX XNXX XXNX XXXA If you try with a code, you would search rows Maybe transpose matrix and again search rows. Now it is up to diagonals. I would like to transpose the matrix so that again horizontal search is possible.
22nd May 2020, 9:39 AM
Oma Falk
Oma Falk - avatar
+ 3
This is the most quick builtin python way to do it >>>list(zip([ [1,2,3], [4,5,6], [7,8,9]]) [[1,4,7],[2,5 8],[3,6,9]]
23rd May 2020, 9:08 AM
NourEddine Yassine
+ 2
Everything works. But np.transpose is best and faster i think. Thanks Jay Matthews
22nd May 2020, 7:13 AM
Lerninn
+ 2
Valmob101 array i think yes but surely not a matrix. I try to find an elegant way for this transition due to a challange that finds words in a matrix. If this transformation is possible with acceptable effort, the search for words can be kept horizontal and not duagonally.
22nd May 2020, 9:15 AM
Oma Falk
Oma Falk - avatar
+ 2
Oma Falk you can also do vertical slice on 2d numpy arrays like arr[0] is first row arr[:,0] is first column Separate the dimensions with comma, and each dimension can have a fixed index or a slice as you would slice any list.
22nd May 2020, 4:36 PM
Tibor Santa
Tibor Santa - avatar
22nd May 2020, 7:08 AM
Lerninn
22nd May 2020, 9:58 AM
Lerninn
23rd May 2020, 3:52 AM
Lerninn
+ 1
https://code.sololearn.com/cSLBAn8q59uv/?ref=app
23rd May 2020, 12:58 PM
Lalis
Lalis - avatar
0
Oma Falk is it an array?
22nd May 2020, 9:02 AM
Lerninn