import torch


def digitize(tensor, bin_boundaries):
    """Implement numpy digitize using torch."""
    result = torch.zeros(tensor.shape).long()
    for boundary in bin_boundaries:
        result += (tensor > boundary).long()
    return result