# How can I specify the distance between values in such row

I have a question, about verifying the value which are near to each other in such row, Is there any algorithm which can determine that ?

Suppose I have a vector $$z_i =$$ {$$z_1 , z_2, z_3, . . . ., z_n$$}, I want first to determine the maximum and minimum values of this vector, then check if the distance between each other value is smaller compare then maximum and to minimum values. In other words, it means dividing the vector into two categories and then check if the value is nearer to first category or second.

Is there any algorithm can do that?

thank you

Just a little bit of python:

import numpy as np

def splitVector(v):
thres = (np.max(v)-np.min(v))/2
return v[v<=thres], v[v>thres]


This will yield two vectors with just the lower or higher elements. If you want to preserve overall size and position of arguments, just a little modification will do it:

import numpy as np

def splitVector(v):
thres = (np.max(v)-np.min(v))/2
return np.where(v<=thres,v,0), np.where(v>thres,v,0)


This will fill in zeros for all elements not fulfilling the condition.

• Thank you so much for your quick answer. Yes, but what is the name of algorithm you are using? I mean is there known algorithm I can use in that case? – Gze Apr 16 '19 at 7:33
• This is so simple, it's not really an algorithm. If you want a name, I guess "categorizing by thresholding" would come close to what is happening there. – Max Apr 16 '19 at 7:50
• @Max ,, Do you know about k-mean algorithm? I think it will be suitable in that case. I'm not sure because I don't know about it so much. – Zeyad_Zeyad Apr 16 '19 at 8:09
• Yes, I know this algorithm. It's a little bit different from what Gze asked, as it will minimize the distance to the cluster points (in this case min and max) for the sum of distances, while what I proposed will do it element wise. It may well be suitable, that depends on what Gze actually wants to do. – Max Apr 16 '19 at 8:32
• Thanks to both of you .. As I checked, we can do it either by K-mean algorithm OR that method provided above. . Thanks again – Gze Apr 16 '19 at 10:16