Given a 2D Array (Python List), I need to find a new 1D such that it contains elements unique in each column. For example:
[1, 1, -1, 1, 0]
[1, -1, -1, 3, 4]
[0, 0, 0, -2, -4]
should give me for example, [1,-1,0,3,4]
.
My trials so far: results is a 2D array of size 3 rows and n columns. last is the array which stores the end result, better said the unique values for each columns. From this array I need to find a 1D array of elements so that they are different.
last = []
for i in range(len(results[0])):
a = results[0][i]
b = results[1][i]
c = results[2][i]
if (a not in last):
last[i] = a
elif (b not in last):
last[i] = b
elif (c not in last):
last[i] = c
But it does not always give correct answer. This fails for input for example:
[1, 2, 3, 3]
[1, 0, -1, 1]
[0, 1, 2, 2]
The output should be for example [0,1,2,3]
or [1,0,3,2]
Any help and hints is appreciated.