Question: NUMPY (Python) 4. Numpy drones We are going to start with the same array we did way up above: But this time, instead of Uber
NUMPY (Python)


4. Numpy drones We are going to start with the same array we did way up above: But this time, instead of Uber drivers, think of these as positions of Alphabet's Wing delivery drones. Now we would like to find the closest drone to a customer who is at 7,1. With the previous example we used Manhattan Distance. With drones, we can compute the distance as the crow flies -- or Euclidean Distance. We probably learned how to do this way back in 7 th grade when we learned the Pythagorean Theorem which states: c2=a2+b2 Where c is the hypotenuse and a and b are the two other sides. So, if we want to find c : c=a2+b2 Distxy=(x1y1)2+(x2y2)2 and for wing_1a who is at [4,5] and our customer who is at [7,1] then the formula becomes: Distxy=(x1y1)2+(x2y2)2=(47)2+(51)2=32+42=9+16=25=5 Sweet! And to generalize this distance formula: Distxy=(x1y1)2+(x2y2)2 to n-dimensions: Distxy=i=1n(xiyi)2 Can you write a function euclidean that takes 3 arguments: droneLocation, droneNames, and an array representing one customer's position and returns the name of the closest drone? First, a helpful hint: [ ] arr=np.array([1,2,3,4]) arr2=np. square (arr) arr2 [ ] locations = np.array ([[4,5],[6,6],[3,1],[9,5]]) drones = np.array [[ "wing_1a", "wing_2a", "wing_3a", "wing_4a" ]) cust = np.array ([6,3]) def euclidean(dronelocation, droneNames, x) : result = " if (distance
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
