Question: I want to modify rows of numpy arrays stored in a list. length of my numpy arrays are not the same. I have several huge numpy arrays stored as list. This is my data (for simplicity I copied only a small list of array):

```
elements= [array([[971, 466, 697, 1, 15, 18, 28],
                 [5445, 4, 301, 2, 12, 47, 5]]),
           array([[5883, 316, 377, 2, 9, 87, 1]])]

```

Then, I want to replace the fourth column of each row with the last one and then delete the last column. I want to have the following result:

```
[array([[971, 466, 697, 1, 28, 18],
        [5445, 4, 301, 2, 5, 47]]),
 array([[5883, 316, 377, 2, 1, 87]])]

```

I tried the following code but it was not successful:

```
length=[len(i) for i in elements] # To find the length of each array
h=sum(length) # to find the total number of rows
for i in range (h):
    elements[:,[4,-1]] = elements[:,[-1,4]]
    elements=np.delete(elements,[-1],1)

```

I am facing the following error:

```
TypeError: list indices must be integers or slices, not tuple

```

I appreciate ay help in advance.

Answer: 
You can do it without loops but it's still slower (1.75 times on large data) than accepted solution:

```
counts = list(map(len, elements))
arr = np.concatenate(elements)
arr[:, 4] = arr[:, -1]
new_elements = np.split(arr[:,:-1], np.cumsum(counts)[:-1])

```

Concatenation is quite slow in `numpy`.
Try this one

```
p=[]
for x in range(len(elements)):
    for y in range(len(elements[x])):
         p.append(list(elements[x][y][:4])+[elements[x][y][-1]]+[elements[x][y][-2]])
print(p)

[[971, 466, 697, 1, 28, 18],
[5445, 4, 301, 2, 5, 47],
[5883, 316, 377, 2, 1, 87]]

```