def ap_at_k_per_query(np_query_labels, k=5):
    """
    Given the binary prediction of labels, this function returns the average precision at specified k
    
    Args:
        np_query_labels : numpy array/ python list with binary values
        k   : cutoff point to find the average precision
    
    Returns:
        Average Precision at k
    """
    ap = 0.0
    running_positives = 0
    for idx, i in enumerate(np_query_labels[:k]):
        if i == 1:
            running_positives += 1
            ap_at_count = running_positives/(idx+1)
            ap += ap_at_count
    return ap/k