def assign_ranks_to_grid(grid, ranks):
    """
    Takes a 2D array of binary numbers represented as strings and a dictionary
    mapping binary strings to integers representing the rank of the cluster
    they belong to, and returns a grid in which each binary number has been
    replaced with the rank of its cluster.
    """
    assignments = deepcopy(grid)
    ranks["0b0"] = 0
    ranks["-0b1"] = -1

    for i in range(len(grid)):
        for j in range(len(grid[i])):
            if type(grid[i][j]) is list:
                for k in range(len(grid[i][j])):
                    assignments[i][j][k] = ranks[grid[i][j][k]]
            else:
                assignments[i][j] = ranks[grid[i][j]]

    return assignments
Takes a 2D array of binary numbers represented as strings and a dictionary
    mapping binary strings to integers representing the rank of the cluster
    they belong to, and returns a grid in which each binary number has been
    replaced with the rank of its cluster.