I would like to ask a question for a numpy array below.
I have a dataset, which has 50 rows and 15 columns and I created a numpy array as such:
I want to compare rows with each other (except than itself), then found the number of rows which satisfies following condition:
there is no other row that
-values are both smaller
-if one is equal, the other one should be smaller
Money Weight
10 80
20 70
30 90
25 50
35 10
40 60
50 10
for instance for row 1: there is no other row which are both smaller on two columns, if one is smaller on the other column row 1 is smaller on the other. Satisfies the condition
for row 3: there is no other row which are both smaller on two columns, it is equal on column weight with row 6 but on money dimension it is smaller. Satisfies the condition
for row 6: there is no other row which are both smaller on two columns. it is equal on weight dimension with row 3 but the value in money is greater. Does not satisfy the condition
Following code works perfect for me to find the rows in the given table:
mask = (arr <= arr[:, None]).all(2).sum(1) < 2
res = df[mask]
print(res)
But I need also compare the table with another row outside the table and should find True or False
For instance:
compare([40,10],table) =False
compare([10,70],table) =True
I have tried bunch of ways to find a proper solution, but could not find a proper way.
I appreciate any suggestions!