1

I have two lists. Each list has three lines. The coordinate system is (x,y,z) from up to down for each list. I tried to use array but it didn't work. Here are my codes.

import numpy as np
p1 = np.array([list(marker_11_x['11:-.X']), list(marker_11_y['11:-.Y']), 
list(marker_11_z['11:-.Z']) ])
p2 = np.array([list(original_x['13:-.X']), list(original_y['13:-.Y']), 
list(original_z['13:-.Z'])])

squared_dist = np.sum(((p1[0]-p2[0])**2+(p1[1]-p2[1] )**2+(p1[3]-p2[3] )**2), 
axis=0)
dist = np.sqrt(squared_dist)

list A = [-232.34, -233.1, -232.44, -233.02, -232.47, -232.17, -232.6, -232.29, -231.65]
[-48.48, -49.48, -50.81, -51.42, -51.95, -52.25, -52.83, -53.63, -53.24]
[-260.77, -253.6, -250.25, -248.88, -248.06, -247.59, -245.82, -243.98, -243.76]

List B = [-302.07, -302.13, -303.13, -302.69, -303.03, -302.55, -302.6, -302.46, -302.59]
[-1.73, -3.37, -4.92, -4.85, -5.61, -5.2, -5.91, -6.41, -7.4]
[-280.1, -273.02, -269.74, -268.32, -267.45, -267.22, -266.01, -264.79, -264.96]

TypeError Traceback (most recent call last) pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

TypeError: an integer is required

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last) in () 1 import numpy as np 2 p1 = np.array([list(marker_11_x['11:-.X']), list(marker_11_y['11:-.Y']), list(marker_11_z['11:-.Z']) ]) ----> 3 p2 = np.array([list(original_x['13:-.X']), list(original_y['13:-.Y']), list(original_z['13:-.Z'])]) 4 5 squared_dist = np.sum(((p1[0]-p2[0])**2+(p1[1]-p2[1] )**2+(p1[3]-p2[3] )**2), axis=0)

E:\ProgramData\Anaconda3\lib\site-packages\pandas\core\series.py in getitem(self, key) 764 key = com._apply_if_callable(key, self) 765 try: --> 766 result = self.index.get_value(self, key) 767 768 if not is_scalar(result):

E:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key) 3101 try: 3102 return self._engine.get_value(s, k, -> 3103 tz=getattr(series.dtype, 'tz', None)) 3104 except KeyError as e1: 3105 if len(self) > 0 and self.inferred_type in ['integer', 'boolean']:

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_value()

pandas_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

KeyError: '13:-.X'

3

1 Answer 1

2

The code and also the formula is gonna be like this :

def distance_finder(one,two) :
    [x1,y1,z1] = one  # first coordinates
    [x2,y2,z2] = two  # second coordinates

    return (((x2-x1)**2)+((y2-y1)**2)+((z2-z1)**2))**(1/2)
2
  • Except in unusual circumstances, this should probably be implemented using NumPy arrays, and if possible leveraging prebuilt tools, like scipy.spatial.distance.cdist. Mar 7, 2019 at 13:39
  • 2
    this is wrong and the function doesn't work as stated here. you need to make the points part of the function if you want this function to work for two lists:def distance_finder(one,two) : [x1,y1,z1] = one # first coordinates [x2,y2,z2] = two # second coordinates dist = (((x2-x1)**2)+((y2-y1)**2)+((z2-z1)**2))**(1/2) return dist @StevenC.Howell
    – Julia
    Jan 8, 2020 at 1:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.