[Python] Understanding weird boolean 2d-array indexing behavior in numpy

Discussão em 'Python' iniciado por Stack, Março 3, 2025.

  1. Stack

    Stack Membro Participativo

    Why does this work:

    a = np.random.rand(10, 20)
    x_range = np.arange(10)
    y_range = np.arange(20)

    a_tmp = a[x_range<5,:]
    b = a_tmp[:, np.in1d(y_range, [3,4,8])]


    and this does not:

    a = np.random.rand(10,20)
    x_range = np.arange(10)
    y_range = np.arange(20)

    b = a[x_range<5, np.in1d(y_range,[3,4,8])]

    Continue reading...

Compartilhe esta Página