def calculate_cardinality(feature_vector, indices=None):
    """
    Calculate cardinality of each features

    :param feature_vector: three dimensional vector with features
    :param indices: list of indices of the features to be extracted
    :return: a map where each key is the index of the feature and the value is a map feature_value,
    value_index.
    For example
     [(0, {'feature1': 1, 'feature2': 2})]

     indicates that the feature is at index 0 and has two values, features1 and features2 with two
     unique index.

     NOTE: the features are indexed from 1 to n + 1. The 0 value is reserved as padding
    """
    columns_length = []
    index = 0
    if not len(feature_vector) > 0:
        return []

    for index_column in range(index, len(feature_vector[0][0])):
        if indices and index_column not in indices:
            index += 1
            continue

        values = set()
        for index_document in range(0, len(feature_vector)):
            for index_row in range(0, len(feature_vector[index_document])):
                value = feature_vector[index_document][index_row][index_column]
                if value != " ":
                    values.add(value)

        values = sorted(values)
        values_cardinality = len(values)

        values_list = list(values)
        values_to_int = {}
        for val_num in range(0, values_cardinality):
            # We reserve the 0 for the unseen features so the indexes will go from 1 to cardinality + 1
            values_to_int[values_list[val_num]] = val_num + 1

        columns_length.append((index, values_to_int))
        index += 1

    return columns_length