Say I have a numpy array:
Y.shape = (n, 3)
where n is the amount of rows in the numpy array.
I split Y based on the values of the second column by following this thread:
distances = [Y[Y[:, 1] == k] for k in np.unique(Y[:, 1])]
Distances is now a list of numpy arrays of N length, where N is the number of possible values in the second column. I create a loop to split each array in distances, repeating the above step, however splitting by the last column this time like so:
for idx, dist in enumerate(distances):
conditions = [dist[dist[:, 2] == k] for k in np.unique(dist[:, 2])]
# Save conditions list and do something with it
How in numpy can I get the row indexes of the oringal Y numpy array that correspond to each numpy array in conditions?
conditionsresults in losing any arrays indistancesthat were 1 row. E.g. if I start withY = np.array([[1,2,3], [3,4,5], [5,6,7], [7,8,9], [10,8,3], [11,3,2]]), the step to finddistanceskeeps all rows, but the final step leaves me withconditions = [array([[10, 8, 3]]), array([[7, 8, 9]])]while discarding all other rows. Is this supposed to happen?enumeratestatement, rows are discarded becauseconditionsis being overwritten during every iteration of the loop. The wholefor idx, dist in enumerate(distances)section only keeps rows from myYarray where 2+ rows have the same value in the middle column.