Question

9. (10 pts) Implement a function sd (x) that takes a list x of data points as input and returns the standard deviation. You can assume that X has at least two elements.use python3

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import math
def sd(X):
n = len(X)
mean = sum(X) / n
diff = [x - mean for x in X]
sq_diff = [d ** 2 for d in diff]
sq_diff_sum = sum(sq_diff)
variance = sq_diff_sum / (n - 1)
sd = math.sqrt(variance)
return sd;
  
X = [4,5,6,7,1,2,3,9,8,10]
print(sd(X));

import math def sd(X): nlen(X) mean sum(X) n diff = [x - mean sq_diff d2 for d in diff] sq_diff_sum sum (sq_diff) variance sq

Output:

sh-4.3$ python3 main.py                                                                                                                                                                                                                                                

3.0276503540974917

Add a comment
Know the answer?
Add Answer to:
use python3 Implement a function sd (x) that takes a list x of data points as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Python)Implement the function deep_list, which takes in a list, and returns a new list which contains...

    (Python)Implement the function deep_list, which takes in a list, and returns a new list which contains only elements of the original list that are also lists. Use a list comprehension. def deep_list(seq): "" "Returns a new list containing elements of the original list that are lists. >>> seq = [49, 8, 2, 1, 102] >>> deep_list(seq) [] >>> seq = [[500], [30, 25, 24], 8, [0]] >>> deep_list(seq) [[500], [30, 25, 24], [0]] >>> seq = ["hello", [12, [25], 24],...

  • Using Python3 Write a function that takes an array of integers and returns it in increasing...

    Using Python3 Write a function that takes an array of integers and returns it in increasing order. There can be negative numbers, but they are treated as positive numbers. Example list= list=[-6,7,6,7,-9,1,0,-3,-2,1,4] Answer list= [0, 1, 1, -2, -3, 4, 6, -6, 7, 7, 3]

  • Implement the function odd_total (xs) that takes a list of list of ints xs and returns...

    Implement the function odd_total (xs) that takes a list of list of ints xs and returns the sum of the odd numbers but skips the numbers on the first row and the last column of xs. You're not allowed to modify xs. You can't use any built-in function or method except int, str, range and len. Example: odd_total ([[1,2,3],[4,5,6], [7,8,9]]) - - > 12

  • Solve in Python 3: Implement function four_letter() that takes as input a list of words (i.e.,...

    Solve in Python 3: Implement function four_letter() that takes as input a list of words (i.e., strings) and returns the sublist of all four letter words in the list. >>> four_letter(['dog', 'letter', 'stop', 'door', 'bus', 'dust']) ['stop', 'door', 'dust']

  • Python3: Write the function findLongestStreak(lst) which takes a list of numbers, lst, and returns the longest...

    Python3: Write the function findLongestStreak(lst) which takes a list of numbers, lst, and returns the longest streak of numbers which occur in the list. A streak of numbers is a list of numbers where each number is one greater than the one that occurred before it- for example, [4, 5, 6, 7]. So findLongestStreak([3, 4, 8, 2, 3, 4, 5, 7, 8, 9]) would return [2, 3, 4, 5]. If there is more than one streak with the longest length,...

  • Using Python 3.6.4: 10.34 Using linear recursion, implement function recDup() that takes a list as input...

    Using Python 3.6.4: 10.34 Using linear recursion, implement function recDup() that takes a list as input and returns a copy of it in which every list item has been duplicated. >>> recDup(['ant', 'bat', 'cat', 'dog']) ['ant', 'ant', 'bat', 'bat', 'cat', 'cat', 'dog', 'dog']

  • Implement the following methods (based on ArrayLists): (JAVA) a) merge method that takes two ArrayLists as...

    Implement the following methods (based on ArrayLists): (JAVA) a) merge method that takes two ArrayLists as input and returns the merged ArrayList containing the elements from both the input lists. b) enumerate method that takes an ArrayList as input and prints the enumerated contents of the input list. c) reverse method that takes an ArrayList as input and returns an ArrayList with the contents of input list in reverse order. Test your method implementations.

  • Write the function deep_contains. It takes as input a number and a list. That list might...

    Write the function deep_contains. It takes as input a number and a list. That list might contain lists as elements, and those lists might contain lists, etc. The deep_contains' function should return a Boolean indicating whether the number is contained inputted list, or a sublist of it, or a sublist of that, and so forth. For example: deep_contains (3, (1,3,5]) returns True deep_contains(3, 11, [3,5]]) returns True deep_contains (3, 1, [[3,4],5),6]) returns True deep_contains (2, (1,3,5]) returns False This function...

  • Write a function called find_max that takes a two-dimensional list as a parameter and returns the...

    Write a function called find_max that takes a two-dimensional list as a parameter and returns the number of the row that sums to the greatest value. For example, if you had the following list of lists: list = [[1, 2, 3], [2, 3, 3], [1, 3, 3]] The first row would be 6, the second 8 and the third 7. The function would, therefore, return 1. You can assume the passed in list of lists has at least one row...

  • Please use PYTHON3 to Create a program that translates English into Pig Latin. The function will...

    Please use PYTHON3 to Create a program that translates English into Pig Latin. The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”. Your program must be case insensitive. You must write the function translate() that takes in a single English word and returns its Pig Latin translation. Remember translate must take only one word as input. #############################################################...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT