Answered step by step
Verified Expert Solution
Question
1 Approved Answer
numpy.ipynb @ Google Colab 1. addToArray(i) Can you write a function addToArr(10) that will add 10 to each cell in our 10001000 matrix. [ ]
numpy.ipynb @ Google Colab
1. addToArray(i) Can you write a function addToArr(10) that will add 10 to each cell in our 10001000 matrix. [ ] def addToArray(i): TO DO Let's take a look at how much time it takes to run that function: [ ] \%time addToArr(10) Can you put all the above in a function. that takes 3 arguments, the location array, the array containing the names of the drivers, and the array containing the location of the customer. It should return the name of the closest driver. [] def findDriver(distanceArr, driversarr, customerArr): result = ' \#\#\# put your code here return result print(findDriver(locations, drivers, cust)) \# this should return clara Can you write a function findClosest that takes 3 arguments: customers, customerNames, and an array representing one customer's ratings and returns the name of the closest customer? Let's break this down a bit. 1. Which line in the NumPy Uber section above will create a new array which is the result of subtracting the Mikaela array from each row of the customers array resulting in array([[1,3,2,4,1],[0,1,1,1,2],[2,3,2,3,1],[1,1,0,1,3],[2,1,1,1,3],[1,3,1,2,3]]) [ ] \# TODO 2. Which line above will take the array you created and generate a single integer distance for each row representing how far away that row is from Mikaela? The results will look like: array([11,5,11,6,8,10]) [ ] \# TO DO Finally, we want a sorted array of indices, the zeroth element of that array will be the closest row to Mikaela, the next element will be the next closest and so on. The result should be array([1,3,4,5,0,2]) Finally we need the name of the person that is the closest. [] \# TO DO Okay, time to put it all together. Can you combine all the code you wrote above to finish the following function? So x is the new person and we want to find the closest customer to x. [ ] def findClosest(customers, customerNames, x ): \# TO DO return ". print(findclosest(customers, customerNames, mikaela)) \# Should print Ben print(findclosest(customers, customerNames, brandon)) \# Should print Ann c=a2+b2 If we want to find the distance between the drone and a customer, x and y in the formula becomes 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 = " \#\#\# your code here return result euclidean (locations, drones, cust)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started