[問題] 如何將numpy創造的二維陣列的值, 向右90度旋轉

看板Python作者 (朦朧尋光)時間8年前 (2017/05/01 23:03), 8年前編輯推噓1(103)
留言4則, 4人參與, 最新討論串1/1
大家好,我使用了numpy.vstack來創造一個二維陣列. 但是想要向右90度旋轉此陣列的值. 變成下面這樣,請問numpy有提供此函式嗎?? inv or .T都不是我想要的方式.也有試過rot90.但好像都不行. .X.X ..X. X..X .... import numpy as np from numpy.linalg import inv def recall_password(cipher_grille): list_cipher_grille = [list(item) for item in cipher_grille] arr_cipher_grille = np.vstack(list_cipher_grille[B) #向右轉值 return "" if __name__ == '__main__': #These "asserts" using only for self-checking and not necessary for auto-testing recall_password( ('X...', '..X.', 'X..X', '....')) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.171.61.185 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1493651030.A.9F9.html

05/01 23:20, , 1F
rot90 ?
05/01 23:20, 1F
rotated = np.rot90(arr_cipher_grille, 1, (1,0))就可以了. 謝謝你

05/02 02:01, , 2F
你的輸入矩陣x的數量跟你想要的矩陣x數量不一樣
05/02 02:01, 2F
後來發現要[list(item) for item in cipher_grille], 先把每個元素用出來. 在塞入np.vstack. 才是4*4. ※ 編輯: angleevil (1.171.61.185), 05/02/2017 21:22:52 ※ 編輯: angleevil (1.171.61.185), 05/02/2017 21:29:43 ※ 編輯: angleevil (1.171.61.185), 05/02/2017 21:54:07 ※ 編輯: angleevil (1.171.61.185), 05/02/2017 22:10:26

05/03 18:32, , 3F
最快方法就是把螢幕往左90度倒
05/03 18:32, 3F

05/04 14:40, , 4F
= =
05/04 14:40, 4F
文章代碼(AID): #1P1qvMdv (Python)