Question
Specific things we would like this function to do in python: a) Take in one input argument that represents a dataset in the form of
Specific things we would like this function to do in python:
a) Take in one input argument that represents a dataset in the form of a 1D numpy array. This array should contain a set of numbers of arbitrary size.
b) To make sure that you didn't just randomly download the function somewhere and to ensure that you understand the concept of scope, declare the variable "writtenBy" and assign your name as a value to it somewhere in the function, but don't return/output this value.
c) The function should return the median absolute deviation as an output.
d) Make sure the function has a clear header - a block of comments at the beginning of the function - as to what inputs the function assumes, what outputs it produces and when it was written. Note: You only need to upload the function code itself to the assignment tab. You do *not* also need to provide the argument. The function should work for *any* 1D numpy array the user wants to give the function (by passing it to the function as an argument within the parentheses) when calling the function.
Hints/suggestions (dont feel bound by this, there are many ways to implement the function):
1. Compute the median. You can do this either by using the median function or sorting the values in the input array and determining the central value yourself.
2. Subtract the median from each number in the input array to get a set of deviations from the median.
3. Take the absolute value of all of these deviations of the median.
4. Find the median of this set of absolute deviations (either by using the median function or by sorting these deviations by magnitude and finding the central value) Input / output
examples:
Input array A: [1,3,5,7,9] medAbsDev(A) returns 2
Input array B: [4.5, 3.2, 1.5, 5.7, 9.3, 2.2, 6.9] medAbsDev(B) returns 2.3
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