Home > Mobile >  Find standard deviation and coefficient of variation for a distribution using numpy.std()
Find standard deviation and coefficient of variation for a distribution using numpy.std()

Time:07-21

Calculate the S.D. and coefficient of variation (C.V.) for the following table : Class : 0-10, 10-20, 20-30, 30-40, 40-50, 50-60, 60-70, 70-80 Frequency : 5, 10, 20, 40, 30, 20, 10, 5​

I know how to solve this problem using mathematical steps as mentioned here https://brainly.in/question/36413297. But how can I solve it using numpy.std(). From the official documentation https://numpy.org/doc/stable/reference/generated/numpy.std.html I can see that numpy.std() expects a list of values as input. But in my case, these are class ranges and corresponding frequencies. So how can I apply numpy.std() in this kind of non-list input problem?

CodePudding user response:

You still have not started working on the code. The implementation of that might differ accordingly. But I suggest that you assign the class ranges a single value as the link you have attached for https://brainly.in/question/36413297.

def midPoint(l):
   return (l[0] l[len(l)-1])/2

Even the mathematical approach is trying to find the midpoint first. After having those midPoints you can implement the numpy.std() to get your SD and Var. Remember upvoting if it solves your question. And give comments if it is still not clear.

CodePudding user response:

Well if you are required to use only the .std() method and no other method, and if your data consist of whole numbers, I suggest you populate your midPoint class list and use the .std() on a single list.

Here is what I mean:

import numpy as np
def formatL1n2(L1,L2):
  L3 = []
  for i in range(len(L1)):
    L3.append([L1[i]]*L2[i])
  L4 = [] # this is to format L3
  for i in L3:
    for j in i:
        L4.append(j)
  return L3
L1 = np.array([5,15,25,35,45,55,65,75])
L2 = np.array([5,10,20,40,30,20,10,5])
L3 = formatL1n2(L1,L2)
st = np.std(L3)
print(L3)

Output:

15.91992077715905
  • Related