In python language, my numpy array is ([12, 1]), and I want to divide it
the value is
([[1],
[2],
[3],
[4],
[5],
[6],
[7],
[8],
[9],
[10],
[11],
[12]])
and I want to make
([[1],[2],[3],[4]],
[[5],[6],[7],[8]]
[[9],[10],[11],[12]])
so I want to divid into thirds (so, the batch_size is 3) how to make the code?
CodePudding user response:
Is it sufficient to reshape as (3,4)
? Otherwise you may have (3,4,1)
>>> arr.reshape(3,4)
array([[ 1, 2, 3, 4],
[ 5, 6, 7, 8],
[ 9, 10, 11, 12]])
>>> arr.reshape(3,4,1)
array([[[ 1],
[ 2],
[ 3],
[ 4]],
[[ 5],
[ 6],
[ 7],
[ 8]],
[[ 9],
[10],
[11],
[12]]])
CodePudding user response:
original_array = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12]]
array1 = original_array[:4]
array2 = original_array[4:8]
array3 = original_array[8:]
print(array1)
print(array2)
print(array3)