Dry Run Solutions

| categories: Practice

Solutions for the problems on the first final dry run.

def F1(table):
    '''Number of subjects more than 10 pounds heavier than the mean'''
    w = table[:, 3]
    m = np.mean(w)
    n = np.sum(w > (m + 10))
    return n

def F2(table):
    '''Mean BMI for men.'''
    w = table[:, 3] / 2.2
    h = table[:, 2] / 3.3
    bmi = w / h ** 2
    m = np.mean(bmi[table[:, 0] == 0])
    return m

def F3(table):
    '''Number of women who are tall, thin, and light'''
    women = table[table[:, 0] == 1]
    tall = women[women[:, 2] > 5.5]
    thin = tall[tall[:, 4] < 26]
    light = thin[thin[:, 3] < 140]
    return len(light)

def F4(table):
    '''Mean and stdev of waist size for men 30 and over'''
    men = table[table[:, 0] == 0]
    old = men[men[:, 1] >= 30]
    waist = old[:, 4]
    mw = np.mean(waist)
    sw = np.std(waist)
    return (mw, sw)