[Python] Insert columns from array into matrices from other array

Discussão em 'Python' iniciado por Stack, Setembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    Suppose I have a numpy array array of matrices

    A=numpy.array([[[1, 0, 0],[1, 1, 0],[0, 1, 0],[1, 1, 1]],[[1, 0, 0],[1, 1, 1],[0, 0, 1],[1, 0, 1]]])

    and another array

    B=np.array([[1,2,3,4],[5,6,7,8]])

    which we interpret as an array of columns to insert into A.

    How can I now insert the columns from B into A, i.e. to obtain

    [[[1, 1, 0, 0],[2, 1, 1, 0],[3, 0, 1, 0],[4, 1, 1, 1]],[[5, 1, 0, 0],[6, 1, 1, 1],[7, 0, 0, 1],[8, 1, 0, 1]]]

    ?

    I tried to use numpy.insert, but unfortunately I did not find to solve this problem with this method.

    Continue reading...

Compartilhe esta Página