5 examples of 'python standard deviation' in Python

Every line of 'python standard deviation' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
100def standard_deviation(self):
101 """Standard deviation of the distribution."""
102 clean, total = self._prepare_for_stats()
103 if not total:
104 return None
105
106 return math.sqrt(clean.variance())
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

592def test_standard_deviation(self):
593 result = standard_deviation(
594 Array.from_list([[20, 20, 20, 18, 25, 19, 20, 20, 20, 20, 40, 30, 1, 50, 1, 1, 5, 1, 20, 20],
595 [20, 20, 20, 2, 19, 1, 20, 20, 20, 1, 15, 1, 30, 1, 1, 18, 4, 1, 20, 20]], dtype.f32)).to_numpy()
596 self.assertAlmostEqual(result[0], 12.363150892875165, delta=1e-4)
597 self.assertAlmostEqual(result[1], 9.51367436903324, delta=1e-4)
232def standardDeviation(self):
233 sd = MU.SD(self.msm)
234 return sd
105def _get_std_deviation(self):
106 variance = sum((t - self.mean)**2 for t in self.times)
107 return (variance / self.total_count) ** 0.5
373def standard_deviation(self, data):
374 """Compute the standard deviation.
375
376 The corresponding FORTRAN code is
377
378 .. code-block:: fortran
379
380 function standard_deviation(a, n) result(var)
381 !DEC$ ATTRIBUTES DLLEXPORT, ALIAS:'standard_deviation' :: standard_deviation
382 integer :: n ! the length of the array
383 double precision :: var, a(n)
384 var = SUM(a)/SIZE(a) ! SUM is a built-in fortran function
385 var = SQRT(SUM((a-var)**2)/(SIZE(a)-1.0))
386 end function standard_deviation
387
388 See the corresponding 64-bit :meth:`~.fortran64.Fortran64.standard_deviation` method.
389
390 Parameters
391 ----------
392 data : :class:`list` of :class:`float`
393 The data to compute the standard deviation of.
394
395 Returns
396 -------
397 :class:`float`
398 The standard deviation of `data`.
399 """
400 n = len(data)
401 nc = ctypes.c_int32(n)
402 datac = (ctypes.c_double * n)(*data)
403 self.lib.standard_deviation.restype = ctypes.c_double
404 return self.lib.standard_deviation(ctypes.byref(datac), ctypes.byref(nc))

Related snippets