USL)))\nhi = float(np.mean(ctq > USL)); lo = float(np.mean(ctq < LSL))\nprint(f'xbar={xbar:.4f} drift={xbar-NOMINAL:+.4f} sigma={sd:.4f}')\nprint(f'scrap={scrap:.1%} (high tail {hi:.1%}, low tail {lo:.1%})')","label":"2 — Run a batch (EDIT the sliders)"},{"code":"def hist(values, lsl, usl, bins=24):\n lo_e, hi_e = min(values.min(), lsl), max(values.max(), usl)\n edges = np.linspace(lo_e, hi_e, bins+1)\n counts, _ = np.histogram(values, edges)\n mx = max(counts.max(), 1)\n out = []\n for i in range(bins):\n c = edges[i]\n mark = 'L' if c <= lsl < edges[i+1] else ('U' if c <= usl < edges[i+1] else ' ')\n bar = '#' * int(counts[i]/mx*40)\n out.append(f'{c:7.3f}{mark}|{bar}')\n return '\\n'.join(out)\nprint(hist(ctq, LSL, USL))","label":"3 — ASCII histogram"},{"code":"# graded seed: fixture_repeat dominates (symmetric-wide), not drift.\ngctq = sample_batch(200, seed=520, tool_wear=tool_wear,\n coolant_drift=coolant_drift, fixture_repeat=fixture_repeat)\ngscrap = float(np.mean((gctq < LSL) | (gctq > USL)))\ngxbar, gsd = gctq.mean(), gctq.std(ddof=1)\ncentered = abs(gxbar - NOMINAL) < 0.006\nproblems = []\nif gscrap >= 0.02 and not centered:\n problems.append(f'mean {gxbar:.3f} is off-center (drift) - reduce tool-wear/coolant to recenter; tolerance wont help.')\nif gscrap >= 0.02 and centered:\n problems.append(f'mean centered but sigma {gsd:.3f} too wide (scatter) - the fixture-repeatability slider is your lever.')\nif fixture_repeat >= 0.03 and gscrap >= 0.02:\n problems.append('on this seed the spread is symmetric-wide: lower fixture_repeat, not tool_wear.')\n\nif gscrap < 0.02:\n print(f'PASS - scrap {gscrap:.1%} < 2.0% on the graded seed by reducing the correct (fixture) driver. '\n 'You read the shape, attributed the spread, and reduced it.')\nelse:\n print(f'FAIL (scrap {gscrap:.1%}) - ' + (problems[0] if problems else 'identify the dominant driver and reduce mainly that one.'))","label":"4 — Autograder (seed M3L2-GATE=520)"}],"intro":"The twin's batch generator in numpy: tool wear adds a ramping right-drift, coolant adds a centered bias, fixture adds symmetric scatter. Move the sliders and re-run to drop scrap.","key":"manufacturing/where-variation-comes-from","kind":"python","title":"Where variation comes from"}">
PYTHON · NUMPY · IN-BROWSER

Where variation comes from

The twin's batch generator in numpy: tool wear adds a ramping right-drift, coolant adds a centered bias, fixture adds symmetric scatter. Move the sliders and re-run to drop scrap.