[Python] IndexError: index 89191 is out of bounds for axis 0 with size 2196

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    I have a problem using the template on a new dataset. I get the error "IndexError: index 89191 is out of bounds for axis 0 with size 2196" when I execute the code:

    book_vector = {}

    for book, group in tqdm(data.groupby( 'Book-Title')):
    book_vector[book] = np.zeros(num_users)
    for i in range(len(group['User-ID'].values)):
    u = group['User-ID'].values
    r = group['Book-Rating'].values
    book_vector[book][int(u - 1)] = r


    Error:

    IndexError Traceback (most recent call last)
    <ipython-input-373-0354cb156c94> in <cell line: 0>()
    7 u = group['User-ID'].values
    8 r = group['Book-Rating'].values
    ----> 9 book_vector[book][int(u - 1)] = r
    10

    IndexError: index 89191 is out of bounds for axis 0 with size 2196


    When using the block try-except the same problem occurs in the next step:

    book_vector['Bag of Bones']


    I expect to get the same result as in the movie example:

    movie_vector = {}

    for movie, group in tqdm(movies_with_ratings.groupby('title')):
    movie_vector[movie] = np.zeros(num_users)

    for i in range(len(group.userId.values)):
    u = group.userId.values
    r = group.rating.values
    movie_vector[movie][int(u - 1)] = r


    movie_vector['Toy Story (1995)']
    -> array([4. , 0. , 0. , 0. , 4. , 0. , 4.5, 0. , 0. , 0. , 0. , 0. , 0. ,
    0. , 2.5, 0. , 4.5, 3.5, 4. , 0. , 3.5, 0. , 0. , 0. , 0. , 0. ,
    3. , 0. , 0. , 0. , 5. , 3. , 3. , 0. , 0. , 0. , 0. , 0. , 0. ,
    5. , 0. , 0. , 5. , 3. , 4. , 5. , 0. , 0. , 0. , 3. , 0. , 0. ,
    0. , 3. , 0. , 0. , 5. , 0. , 0. , 0. , 0. , 0. , 5. , 4. , 0. ,
    4. , 0. , 2.5, 0. , 0. , 5. , 0. , 4.5, 0. , 0. , 0.5, 0. , 4. ,
    0. , 0. , 0. , 2.5, 0. , 0. , 0. , 4. , 0. , 0. , 3. , 3. , 4. ,
    0. , 3. , 0. , 0. , 5. , 0. , 4.5, 0. , 0. , 0. , 0. , 4. , 0. ,
    0. , 0. , 4. , 0. , 0. , 0. , 0. , 3. , 0. , 0. , 0. , 0. , 0. ,
    0. , 3.5, 0. , 4. , 0. , 0. , 4. , 0. , 0. , 0. , 0. , 0. , 3. ,
    0. , 2. , 0. , 3. , 4. , 0. , 4. , 0. , 0. , 3. , 4. , 0. , 0. ,
    3.5, 5. , 0. , 0. , 0. , 0. , 0. , 5. , 0. , 2. , 0. , 3. , 4. ,
    0. , 0. , 4.5, 4. , 4. , 0. , 0. , 0. , 0. , 5. , 3.5, 0. , 4.5,
    0. , 5. , 0. , 0. , 0. , 0. , 0. , 5. , 4. , 4. , 0. , 0. , 4. ,
    0. , 0. , 4. , 4. , 0. , 0. , 0. , 0. , 4. , 0. , 2. , 0. , 0. ,
    0. , 0. , 0. , 0. , 3.5, 5. , 4. , 0. , 0. , 0. , 5. , 0. , 0. ,
    0. , 0. , 0. , 0. , 3.5, 3. , 0. , 3. , 4. , 0. , 3.5, 5. , 0. ,
    0. , 3.5, 0. , 0. , 3.5, 0. , 0. , 5. , 0. , 0. , 3.5, 3. , 5. ,
    0. , 0. , 0. , 0. , 4. , 5. , 0. , 0. , 0. , 0. , 0. , 0. , 5. ...])

    Continue reading...

Compartilhe esta Página