[Python] arrays of size 0 in numpy

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    For reasons, I need to work with arrays that can have zeros in their shapes. However, I am encountering an issue. Here's an example:

    import numpy as np

    arr = np.array([[]])
    assert arr.shape == (1,0)
    arr.reshape((1,0)) # no problem (nothing changes)
    arr.reshape((-1,0)) # ValueError: cannot reshape array of size 0 into shape (0)


    I always thought that -1 for a reshape operation means the product of all the remaining dimensions, i.e. 1 in this case. Is this a bug or am I not understanding how this should work?

    Continue reading...

Compartilhe esta Página