I'm trying to create a new array based on an index, which is the first element in each row. I feel like i'm missing something really simple here.
array looks like this and the first number in the row is the index.
[[ 1 0 1 2 3 4]
[ 1 5 6 7 8 9]
[ 2 10 11 12 13 14]
[ 2 15 16 17 18 19]
[ 4 20 21 22 23 24]]
the outcome I would like would be such like:
array 1:
range 1=
[[ 1 0 1 2 3 4]
[ 1 5 6 7 8 9]]
array 2:
range2 =
[[ 2 10 11 12 13 14]
[ 2 15 16 17 18 19]]
Array 3:
range 3=
[[ 4 20 21 22 23 24]]
This is the code I currently have, but I have N number possible index numbers and I can't obviously make an if statement for all of them. I was planning on using a list then converting that list in an numpy array. I've also looked at zipping them before using hstack but I couldn't get that to work either.
import numpy as np
data = np.arange(25).reshape(5,5)
indexList = np.array(([[1,1,2,2,4]]))
indexList = np.transpose(indexList)
array = np.hstack((indexList, data))
range1 = []
range2 = []
range3 = []
for row in array:
if row[0] == 1:
range1.append(row)
if row[0] == 2:
range2.append(row)
if row[0] == 3:
range3.append(row)