[Python] What does array operator '[:, None]' do in Python? [duplicate]

Discussão em 'Python' iniciado por Stack, Junho 21, 2025.

  1. Stack

    Stack Membro Participativo

    Given

    x=np.arange(5)


    Which results in

    array([0, 1, 2, 3, 4])


    What is x[:,None] doing?

    It makes

    array([[0],
    [1],
    [2],
    [3],
    [4]])


    I can see it is turning each element of array x into a subarray of 1 element.

    But why, and for next time, how would I search Python documentation to find this operator and how it works?

    Continue reading...

Compartilhe esta Página