1. Engineering
  2. Computer Science
  3. also heres my code for mean1dnp and my current code...

Question: also heres my code for mean1dnp and my current code...

Question details

Problem 4 (30 points) Given a 1D array, calculate its sample standard deviation, std, in place using numpy Employ the two-pass algorithm as formulated below: where v is the mean of the vector from mean!dnpC) . Same as Problem 2, BUT: Constraint: Do not use for loops or the built-in std or mean methods. Hint: Your code should be shorter than the list implementation.Expected output: std1dnp([1,2,3,4]) - 1.2909944487358056


Also, here's my code for mean1dnp:

In [103]: import numpy as np import math In [191]: def meanidnp (v): Given a 1D numpy array, return its mean if (len(v)) else: raise ValueError() xnp.sum(v, axis-0) return x/len (v)

And my current code, which works for the first expected output, but not the second one (ignore the print statements, was using those to test the function):

In [832]: def std1dnp(v): Given a 1D array, return its std if (len(v) <1): else: raise ValueError) print(v) print(mean1dnp (v)) vnp.array(v - meanidnp (v)) print(v) v-np.array((v*v)) print(v) v = np.sqrt(np.sum(v)/(len(v)-1)) returnv

Any help would be much appreciated!



Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution