def load_data_from_array(array, users_to_i={}, items_to_i={}):
    """
      Loads data from an array of tuples of the form:

          (user_id, item_id)

      Initial mappings from user and item identifiers
      to integers can be passed using `users_to_i`
      and `items_to_i` respectively.

      This function will return a data array consisting
      of (user, item) tuples, a mapping from user ids to integers
      and a mapping from item ids to integers.
    """
    data = []
    if len(users_to_i.values()) > 0:
        u = max(users_to_i.values()) + 1
    else:
        u = 0
    if len(items_to_i.values()) > 0:
        i = max(items_to_i.values()) + 1
    else:
        i = 0
    for user, item in array:
        if not users_to_i.has_key(user):
            users_to_i[user] = u
            u += 1
        if not items_to_i.has_key(item):
            items_to_i[item] = i
            i += 1
        data.append((users_to_i[user], items_to_i[item]))
    return data, users_to_i, items_to_i
