I have a 2d array, it has huge number of rows(lager than 5000).
For the sake of simplicity,assume A is a simple version of my matrix
A=([[1,2,2,3,3,3],
[[2,1,1,7,7,7],
[[4,4,1,1,1,1]])
Now, A only has 3 rows:
the 1st row has 3 values: one 1, two 2,three 3.
the 2nd row has 3 values, one 2, two 1,three 7.
the last row has 2 values, two 4, four 1.
now I can easily find the majority value for each row:
1st is 3, 2nd is 7, 3rd is 1. (means my code already find each rows majority value and store them as [3,7,1] )
what I want to do is set each row's majority value to 0.
means set
A=([[1,2,2,0,0,0],
[[2,1,1,0,0,0],
[[4,4,0,0,0,0]])
A is just a simple instance.My matrix has huge number of rows.
So, how to do this thing more easily and efficiently?
I don't want to write a for loop to set the value for each row.
(means i can do A[0,A[0,:]==3]=0, A[1,A[1,:]==7]=0, A[2,A[2,:]==1]=0,but this is too complicated)
what I want is a form like this:
A[:,A[:,:]==[3,7,1]]=0
but numpy doesn't has this ability.
Can any one give me an efficient method for this? thank u very much!!!
For more generally situation, If I want to set each rows 1st biggest value to 0, 2nd biggest value to -1, 3rd biggest(if exist) value to -2 ...., how to do this?
means set:
A=([[-2,-1,-1,0,0,0],
[[-2,-1,-1,0,0,0],
[[-1,-1,0,0,0,0]])