Home > other >  Iterate 45 times over a numpy.ndarray of shape (45, 2040, 5200,3) can't concatenate int to tupl
Iterate 45 times over a numpy.ndarray of shape (45, 2040, 5200,3) can't concatenate int to tupl

Time:02-22

I'm trying to iterate 45 images data, which is of shape (2040,5200) and 3 color channels. The numpy array data has shape (45,2040,5200,3). I'm trying to get the (2040,5200) values of all 45 images as np.zeros

marker_image=[]
i=0

for i in enumerate(data):
    imm = np.zeros(data[i].shape[:2],dtype=np.uint8)
    #marker_image.npbytes
    marker_image.append(imm)
    i 1 

getting this error 'can only concatenate tuple (not "int") to tuple'

How do I get this resolved?

CodePudding user response:

The error you are sticking with is not related to numpy or list or anything but just the way you are using enumerate. This function, which takes an iterable value, such as list, numpy array and variables like them, gives you a tuple. The first element of the tuple is the index of the value and the second value is the element in the iterable variable. So, i is a tuple, and you are trying to call i = 1 on a tuple which is not acceptable. enumerate is usually being used in this way:

marker_image=[]
i=0

for index, value in enumerate(data):
    imm = np.zeros(data[i].shape[:2],dtype=np.uint8)
    #marker_image.npbytes
    marker_image.append(imm)
    # What you want to do in the rest code
  • Related