Tag Info

New answers tagged

2

ClearAll[distF1, distF2] distF1 = With[{p = Intersection @@ (Flatten@ SparseArray[#]["NonzeroPositions"]&/@ #)}, -Length @ p] &; distF2 = With[{p = Intersection @@ (Flatten@SparseArray[#]["NonzeroPositions"]&/@#)}, -Total[Differences@p]] &; Example: vec1 = {1, 0, 0, 0, 0, 1, 0, 1}; vec2 = {1, 0, 1, 0, 0, 1, 0, 0}; vec3 = ...


1

I have trouble following your examples but perhaps you can Split your vectors and compare length: vec1 = {1, 0, 0, 0, 0, 1, 0, 0}; vec3 = {0, 0, 0, 0, 1, 1, 0, 0}; vec5 = {1, 0, 0, 1, 0, 0, 0, 1}; Length /@ Split /@ {vec1, vec3, vec5} {4, 3, 5} Combine this with HammingDistance or alternatives with whatever weighting you prefer.



Top 50 recent answers are included