Created
January 14, 2014 06:27
-
-
Save countrymarmot/8413981 to your computer and use it in GitHub Desktop.
caculate Cp and Cpk using python numpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import numpy as np | |
def Cp(mylist, usl, lsl): | |
arr = np.array(mylist) | |
arr = arr.ravel() | |
sigma = np.std(arr) | |
Cp = float(usl - lsl) / (6*sigma) | |
return Cp | |
def Cpk(mylist, usl, lsl): | |
arr = np.array(mylist) | |
arr = arr.ravel() | |
sigma = np.std(arr) | |
m = np.mean(arr) | |
Cpu = float(usl - m) / (3*sigma) | |
Cpl = float(m - lsl) / (3*sigma) | |
Cpk = np.min([Cpu, Cpl]) | |
return Cpk | |
if __name__ == "__main__": | |
#a1 = np.random.randn(10) | |
#print a1 | |
#print Cp(a1, 1, -1) | |
#print Cpk(a1, 1, -1) | |
a1 = np.arange(0, 10) | |
print a1 | |
print Cp(a1, 10, 0) | |
print Cpk(a1, 10, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not Cpk. Instead the calculation is Ppk because the way of sigma calculation.