Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with list
#1
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
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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...
Reply
#4
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
yeah it's an array, it works as
A[a:b,c:d]
thanks for your help :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with "Number List" problem on HackerRank Pnerd 5 2,109 Apr-12-2022, 12:25 AM
Last Post: Pnerd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020