I would like to build a matrix by adding the rows, starting from:
[ 5 20 31 32 36 3 10 25 27 40]
[ 3 10 25 27 40 18 19 20 40 41]
[18 19 20 40 41 6 22 26 29 48]
[ 6 22 26 29 48 8 11 23 27 35]
to get:
[[ 5 20 31 32 36 3 10 25 27 40],
[ 3 10 25 27 40 18 19 20 40 41],
[18 19 20 40 41 6 22 26 29 48],
[ 6 22 26 29 48 8 11 23 27 35]]
using this code:
#initialize the target matrix
arr = np.empty((0, 10), int)
for current_line in statistics.values:
if len(previous_line) > 0:
#build an array row of 10 elements by 2 array with lenght 5
row = np.append(np.array(previous_line), np.array(current_line))
#arr = np.append(arr, row, axis=0)
#fails with following Exception ValueError: all the input arrays must have same number of dimensions
print(row)
previous_line = current_line
print(row.shape) gives (10,) back. I tried using row.T but it fails as well. Have you any suggestion?
Thank you very much! Bye Fabio
previous_line? You createarrbut don't use it. Same forrow.