![]() |
Problem with list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Problem with list (/thread-17803.html) |
Problem with list - yukysky - Apr-24-2019 Hi, I have a problem with my array list in pyhton while using cv2. I have an array list that looks like that: A=[[[RGB],[RGB]],....,[[RGB],[RGB]]] A[i] = heigh of the image A[][j] = the lenght of the picture I need to shorten the heigh and the lenght of A, to do so A=A[a:b] (with [a,b] the only portion i need) and i'd like to do : for i in range(len(A)): A[i]=A[i][c:d] #(to shorten each A[i] the portion i need)but it doesn't work as it doesn't do what i'd suppose it'd do... is there is a way to remove those unwanted part ? (because del and remove doesn't work as for del, it's an array and it doesn't like it, and for remove i don't know what color is in that pixel so i can't remove the specific pixel i don't want... Yuky RE: Problem with list - ichabod801 - Apr-24-2019 How is it not working? It looks good to me. I made my own version: x = [[1, 2, 3], [1, 2, 3], [1, 2, 3]] for index in range(len(x)): x[index] = x[index][:2] x = x[:2] print(x)Which prints [[1, 2], [1, 2]]. However, you generally want to iterate directly over the list instead of it's indexes, so I would do something like this: y = [[1, 2, 3], [1, 2, 3], [1, 2, 3]] z = [] for row in y[:2]: z.append(row[:2]) y = z print(z)Which has the same result. RE: Problem with list - yukysky - Apr-24-2019 Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Users\User\Desktop\CPGE\Test Recadrage.py", line 98, in recadrer frame[i]=frame[i][d[l]:b[l]] ValueError: could not broadcast input array from shape (1310,3) into shape (1920,3) import cv2 cap = cv2.VideoCapture('185012.mov') frame = cap.read()[1] frame=frame[c[l]:a[l]] for i in range(len(frame)): frame[i]=frame[i][d[l]:b[l]]That's the error it shows me... RE: Problem with list - ichabod801 - Apr-24-2019 So it's not a standard Python list. Is cv2 using numpy arrays, or does it have it's own arrays? I would look into the documentation for whatever array type it is. Also, my preferred method above of building a new list might get around the reshaping issue. RE: Problem with list - yukysky - Apr-24-2019 yeah it's an array, it works as A[a:b,c:d] thanks for your help :) |