Hi everyone and please excuse my limited programming knoweledge. I have two arrays like:
A =([[ 0.10111977, 0.5511177 , 0.49532397, 0.42136468, 0.43345532],
[ 0.3812068 , 0.97679566, 0.20473656, 0.40256096, 0.32423426],
[ 0.2387294 , 0.88714084, 0.01064819, 0.48275173, 0.78234234]])
B = ([[ 0.10111977, 0.5511177 , 0.49532397],
[ 0.2387294 , 0.88714084, 0.01064819]])
(they actually have many thousands of lines but just to demonstrate the problem). I'd like to compare the two in order to find which of the lines in B are also present in A in order to copy the relevant row into a new array that would look like:
C =([[ 0.10111977, 0.5511177 , 0.49532397, 0.42136468, 0.43345532],
[ 0.2387294 , 0.88714084, 0.01064819, 0.48275173, 0.78234234]])
The easy (brute force) solution I tried is to do something like:
for rowB in B:
for rowA in A:
if A[rowA,0]==B[rowB,0] and A[rowA,1]==B[rowB,1] and A[rowA,2]==B[rowB,2]:
C.extend(row)
continue
now this will work but as I said my datasets are huge and it takes for ever. Is there an easier\faster way to do this? I have thought of interpolation but I don't see how it can be done with those data.
ifcondition to:cmp(rowB, rowA[:3]) == 0-- that'll make it easier to read but don't know if any faster. Your problem is that you go through the entirety of A for each row of B and I don't think there's a good shortcut out of that.