def compute_item_means(ratings):
    """
        Computes the mean of ratings for each item (row)
        :param ratings: initial data set (sparse matrix of size nxp, n items and p users)
        :return: List of length n. means[i] is the mean of the ratings of item i.
    """
    means = [0 for _ in range(ratings.shape[0])]
    for item in range(ratings.shape[0]):

        # compute the mean of non-zero rating for current user
        current_ratings = ratings[item]
        current_non_zero_ratings = current_ratings[current_ratings.nonzero()]

        if current_non_zero_ratings.shape[1] != 0:
            mean = current_non_zero_ratings.mean()
            mean = min(5, mean)
            mean = max(1, mean)
            means[item] = mean

    return means