2021-12-19

Group the lines of an array based on a number

I have an array with 100 lines and 5 columns. I would like to group them in separate arrays, based on a number given in the 5th column. The 5th column contains integer numbers from 0 to N (0, 1, 2, ...N).

So for N=2, values in column 5th will be 0, 1, 2

thus I would like to create 3 arrays with the lines having 0, 1, 2 respectively.

here is the code in python for N=3:

df_array_with_clusters=... 

for i in range(len(df_array_with_clusters)):

 if df_array_with_clusters[i, -1]== 0:

  cluster_0[i,:] = df_array_with_clusters[i, :-1]

 elif df_array_with_clusters[i, -1]== 1:
  cluster_1[i,:] = df_array_with_clusters[i, :-1]

 else:
  cluster_2[i,:] = df_array_with_clusters[i, :-1]

thanks



from Recent Questions - Stack Overflow https://ift.tt/3Jdwz8H
https://ift.tt/eA8V8J

No comments:

Post a Comment