+ 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.
17 Antworten
+ 4
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 with rotate:
Can one transpose
12
34
To
1
23
4
?
+ 3
Arrray2= zip(*Array)
but I would propose numpy indeed.
+ 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.
+ 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]]
+ 2
Everything works. But np.transpose is best and faster i think. Thanks Jay Matthews
+ 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.
+ 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.
+ 1
Oma Falk It worked thanks alot.
https://code.sololearn.com/cgL2V7TjYXU8/?ref=app
+ 1
𝐊𝐢𝐢𝐛𝐨 𝐆𝐡𝐚𝐲𝐚𝐥 thanks.it also worked.
+ 1
Oma Falk you mean kinda this?:
https://code.sololearn.com/cMnwet1XIgL5/?ref=app
+ 1
Oma Falk another way:
https://code.sololearn.com/cB34VJJIlNFr/?ref=app
+ 1
https://code.sololearn.com/cSLBAn8q59uv/?ref=app
0
Oma Falk is it an array?