'Looping (for) through some data, concatenating along the way, appending to a list in final, but dimensions don't match in python
Here is the code:
#new_right_v2 = []
for i in range(rows):
r1_p5_first_half = np.concatenate( (new_right[i,:312].reshape(1,-1), new_right[i,625:937].reshape(1,-1), new_right[i,1250:1562].reshape(1,-1), new_right[i,1875:2187].reshape(1,-1)),axis=1)
#print(r1_p5_first_half.shape)
r1_p5_second_half = np.concatenate( (new_right[i,313:625].reshape(1,-1), new_right[i,938:1250].reshape(1,-1), new_right[i,1563:1875].reshape(1,-1), new_right[i,2187:2499].reshape(1,-1)),axis=1)
new_right_v2.append(r1_p5_first_half)
new_right_v2.append(r1_p5_second_half)
new_right_v2
But when I run to check dimensions:
for i in range(40):
print(new_right_v2[i].shape)
This output comes: (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (2, 1248) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624) (4, 624)
I don't know what happens after 10th iteration. Any idea?
Solution 1:[1]
I am actually not sure what dimensions are you checking, as new_right_v2 seems to be a list
Maybe you can apply the operations matrix-wise to all rows at once?
first_half = np.concatenate(
new_right[:,:312],
new_right[:,625:937],
new_right[:,1250:1562],
new_right[:,1875:2187])
).T
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zaero Divide |
