如何对子矩阵的边缘进行圆移

时间:2019-04-16 01:07:31

标签: python python-3.x matrix

我只想在python中旋转子矩阵的边缘 但是我不知道怎么办

1, 2, 3, 4, 5, 6
7, 8, 9, 10, 11, 12
13, 14, 15, 16, 17, 18
19, 20, 21, 22, 23, 24
25, 26, 27, 28, 29, 30

我想将上方矩阵设为下方

enter image description here

我如何在python中做到尽可能简单?

src = [[1, 2, 3, 4, 5, 6],
       [7, 8, 9, 10, 11, 12],
       [13, 14, 15, 16, 17, 18],
       [19, 20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29, 30]]
det = [[2, 3, 4, 5, 6, 12],
       [1, 8, 9, 10, 11, 18],
       [7, 13, 14, 15, 16, 17],
       [19, 20, 21, 22, 23, 24],
       [25, 26, 27, 28, 29, 30]]

1 个答案:

答案 0 :(得分:0)

import tkinter as tk


rectangle_values = []
rectangle_number = []
temp_recta = []
temp_rectn = []
rcta = []
rctn = []
s = 0
t = 0
u = 0
v = 0
w = 0
g = 0
h = 0

def open_window(rect, mnw,mxw,mnl,mxl):
    window.title('Rectangles')
    global s
    global t
    global u
    global v
    global w
    global g
    global h
    global rectangle_values
    global rectangle_number


    s = mnw
    t = mxw
    u = mnl
    v = mxl
    g = rect
    x, y, z, j = 400, 405, 405, 1

    l9 = tk.Label(canvas, text="각 Component 입력 정보", font= "calibri 13", bg="white")
    canvas.create_window(30,350, window=l9, anchor=tk.NW)

    l10 = tk.Label(canvas, text="CW", font= "calibri 14", bg="white")
    canvas.create_window(200,370, window=l10, anchor=tk.NW)

    l11 = tk.Label(canvas, text="CH", font= "calibri 14", bg="white")
    canvas.create_window(335,370, window=l11, anchor=tk.NW)    

    l12 = tk.Label(canvas, text="공급사 모재 면적 정보", font= "calibri 13", bg="white")
    canvas.create_window(460,350, window=l12, anchor=tk.NW) 

    l12 = tk.Label(canvas, text="Area", font= "calibri 14", bg="white")
    canvas.create_window(470,380, window=l12, anchor=tk.NW)

    poscoimg3 = tk.PhotoImage(file="C:/Users/sel/Desktop/poscoimg3.png")
    canvas.create_image(700,360, image=poscoimg3, anchor=tk.NW)

    area_var = tk.DoubleVar()
    entry_area_number = tk.Entry(canvas, textvariable=area_var)
    canvas.create_window(590,395, window=entry_area_number)
    w = area_var.get()



    for i in range(0, rect * 2):         
        if (i % 2) == 0: 
            l1 = tk.Label(canvas, text="Component %d" %(j), font= "calibri 13", bg="white")
            canvas.create_window(30, x, window=l1, anchor=tk.NW)
            rectangle_values.append(tk.StringVar())
            j +=1
            x +=30



            en = tk.Entry(canvas, textvariable=rectangle_values[i])
            canvas.create_window(150, y, window=en, anchor=tk.NW)
            y +=30

        if (i % 2) != 0:
            rectangle_values.append(tk.StringVar())            
            en = tk.Entry(canvas, textvariable=rectangle_values[i])
            canvas.create_window(285, z, window=en, anchor=tk.NW)
            z +=30
    h=y       

    #for j in range(0, rect):
        #rectangle_number.append(tk.StringVar())            
        #en = tk.Entry(canvas, textvariable=rectangle_number[j])
        #canvas.create_window(400, f, window=en, anchor=tk.NW)
        #f +=20

    proceed_button = tk.Button(canvas, text="Run", command=lambda: first_step() )
    canvas.create_window(470, 420, window=proceed_button, anchor=tk.NW)
    canvas.configure(scrollregion=canvas.bbox("all"))

window = tk.Tk()
window.configure()

ws = window.winfo_screenwidth()
hs = window.winfo_screenheight()
w = 980  # width for the Tk root
h = 600  # height for the Tk root
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)

window.geometry('%dx%d+%d+%d' % (w, h, x, y))
canvas = tk.Canvas(window, bg="white", width=980, height=600, highlightthickness=0)
canvas.pack()
canvas_scroll = tk.Scrollbar(canvas, command=canvas.yview)
canvas_scroll.place(relx=1, rely=0, relheight=1, anchor=tk.NE)
canvas.configure(yscrollcommand=canvas_scroll.set, scrollregion=())

l0 = tk.Label(canvas, text="강재 NESTING 최적화 프로그램", font= "calibri 32",fg="royalblue4",bg="white" )
canvas.create_window(200,70, window=l0, anchor=tk.NW)

l00 = tk.Label(canvas, text="제조사 시트 입력 정보", font= "calibri 15", bg="white" )
canvas.create_window(30,155, window=l00, anchor=tk.NW)

photo = tk.PhotoImage(file="C:/Users/sel/Desktop/posco.png")
canvas.create_image(800,10, image=photo, anchor=tk.NW)


line = tk.PhotoImage(file="C:/Users/sel/Desktop/line.png")
canvas.create_image(0,130, image=line, anchor=tk.NW)


poscoimg1 = tk.PhotoImage(file="C:/Users/sel/Desktop/poscoimg1.png")
canvas.create_image(500,180, image=poscoimg1, anchor=tk.NW)

poscoimg2 = tk.PhotoImage(file="C:/Users/sel/Desktop/poscoimg2.png")
canvas.create_image(0,340, image=poscoimg2, anchor=tk.NW)

l1 = tk.Label(canvas, text="MIN", font= "calibri 14", bg="white")
canvas.create_window(210,180, window=l1, anchor=tk.NW)


l2 = tk.Label(canvas, text="MAX", font= "calibri 14", bg="white")
canvas.create_window(340,180, window=l2, anchor=tk.NW)


l3 = tk.Label(canvas, text="Sheet 폭(SW)", font= "calibri 13", bg="white")
canvas.create_window(33,200, window=l3, anchor=tk.NW)

minw_var = tk.DoubleVar()
entry_minw_number = tk.Entry(canvas, textvariable=minw_var)
canvas.create_window(220,215, window=entry_minw_number)

maxw_var = tk.DoubleVar()
entry_maxw_number = tk.Entry(canvas, textvariable=maxw_var)
canvas.create_window(355,215, window=entry_maxw_number)

l4 = tk.Label(canvas, text="Sheet 높이(SH)", font= "calibri 13", bg="white")
canvas.create_window(33,230, window=l4, anchor=tk.NW)

minl_var = tk.DoubleVar()
entry_minl_number = tk.Entry(canvas, textvariable=minl_var)
canvas.create_window(220,240, window=entry_minl_number)

maxl_var = tk.DoubleVar()
entry_maxl_number = tk.Entry(canvas, textvariable=maxl_var)
canvas.create_window(355,240, window=entry_maxl_number)

l5 = tk.Label(canvas, text="소요 Component 개수", font= "calibri 13", bg="white")
canvas.create_window(33,260, window=l5, anchor=tk.NW)

rect_var = tk.IntVar()
entry_rect_number = tk.Entry(canvas, textvariable=rect_var)
canvas.create_window(290,270, window=entry_rect_number)

submit_button = tk.Button(canvas, text="Submit", command=lambda: open_window(rect_var.get(),\
                minw_var.get(), maxw_var.get(),minl_var.get(),maxl_var.get()))
canvas.create_window(200, 290, window=submit_button, anchor=tk.NW)
canvas.bind_all('<MouseWheel>', lambda event: canvas.yview_scroll(int(-1*(event.delta/120)), "units"))

window.title("Rectangle Configuration")
window.mainloop()

输出: s=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]] m=[] def up(): k=0 l=[0]*len(s[0]) for i in range(len(s[0])-1): l[i]=s[k][i+1] l[-1]=s[k+1][-1] m.append(l) def down(): k=len(s)-1 l=[0]*len(s[0]) for i in range(len(s[0])-1): l[i+1]=s[k][i] l[0]=s[k-1][0] m.append(l) def mid(): for j in range(1,len(s)-1): l=[0]*len(s[0]) l[0]=s[j-1][0] for k in range(1,len(s[0])): l[k]=s[j][k] l[-1]=s[j+1][-1] m.append(l) up() mid() down() print(m) 因此,这里s是矩阵,其边界必须逆时针旋转1个元素。 m是最终矩阵。函数up(),mid()和down()分别将第一个列表,中间列表和最后一个列表附加到m。您将必须对数组进行切片以执行操作。