Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Euclidean Distance from Ideal best and from Ideal Worst

Let’s consider this table below:

Mobile Battery(mAh) RAM(GB) Storage(GB) ED from Ideal best ED from Ideal worst
Sansung 1000 4 2
iPhone 8000 6 3
Motorola 3000 3 1

Formula for ED from Ideal best = √(( Battery(mAh)- Max of Battery(mAh))^2 + (RAM(GB) – Max of RAM(GB) )^2 + ( Storage(GB) – Max of Storage(GB))^2)

Formula for ED from Ideal Worst = √(( Battery(mAh)- Min of Battery(mAh))^2 + (RAM(GB) – Minof RAM(GB) )^2 + ( Storage(GB) – Min of Storage(GB))^2)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

For instance, value for Samsung mobile should be √((1000-8000)^2+(4-6)^2+(2-3)^2) = 7000.00035714

Can Anyone help me to write a function in Python where these two formulas can apply for each rows for ED from Ideal best and ED from Ideal worst?

So far I’ve tried this:

df["Euclidean Distance from ideal best"]= np.sqrt((df["Battery(mAh)"]-df["Battery(mAh)"].max()).pow(2) + (df["RAM(GB)"]-df["RAM(GB)"].max()).pow(2) + (df["Storage(GB)"]-df["Storage(GB)"].max()).pow(2))

>Solution :

It works fine by me. Just change the typo df1->df:

df["Euclidean Distance from ideal best"] = np.sqrt(
    (df["Battery(mAh)"] - df["Battery(mAh)"].max())**2 + 
    (df["RAM(GB)"]-df["RAM(GB)"].max())**2 + 
    (df["Storage(GB)"]-df["Storage(GB)"].max())**2)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading