Skip to content
Permalink
b494d95d4b
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
32 lines (24 sloc) 750 Bytes
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""This module provides common methods for manipulating data"""
from collections import defaultdict
def stratify(X, Y):
"""Stratifies Y based on unique values of X.
Args:
X (sequence): sequence of discrete outcomes
Y (sequence): sequence of discrete outcomes
Returns:
(dict): list of Y-values for a X-value
"""
Y_grps = defaultdict(list)
for i, x in enumerate(X):
Y_grps[x].append(Y[i])
return Y_grps
def to_nested(X):
"""Converts the given sequence to a nested sequence.
Args:
X (sequence): sequence of discrete outcomes
Returns:
(nested sequence): nested sequence of X
"""
return [[x] for x in X]