Question: This exercise is based on the Python file distance.py . We suggest that you download the file distance.py and open it in Spyder because it
This exercise is based on the Python file
distance.py We suggest that you download the file
distance.py and open it in Spyder because it will make it easier for you to follow the description below.
The Python file distance,py defines two numpy arrays with the name pos and ref. The array pos has a shape of You can consider each row of pos is used to store the position of an object. For example, pos and pos store, respectively, the and coordinates of the first object.
The array elements ref and ref store, respectively, the and coordinates of a reference point.
Your task is to compute the distance between each of the objects in pos from the reference point. If the coordinates of the object is and those of the reference point are then their distance is given by the formula:
We require that you complete this task using numpy functions and arithmetic operators. You are not allowed to use any loops. You can also find the expected answers in the file
distance.py
Hints: You will need to use numpy broadcasting discussed in Week As lecture and some numpy mathematical functions link to numpy manual page on maths functions
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
