[Python] I have an np array of a number single entry lists and I want to add 1 to each single...

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

  1. Stack

    Stack Membro Participativo

    I have created the following array, called X:

    array([[6.575],
    [6.421],
    [7.185],
    [6.998],
    [6.43 ],
    [6.012],
    [6.172],
    [5.631],
    [6.004],
    [6.377],
    [6.03 ]])


    and I would like to create

    array([[6.575, 1],
    [6.421, 1],
    [7.185, 1],
    [6.998, 1],
    [6.43, 1],
    [6.012, 1],
    [6.172, 1],
    [5.631, 1],
    [6.004, 1],
    [6.377, 1],
    [6.03, 1]])


    I have tried X = np.array( [ [value,1] for value in X ] ) but I get the error:

    ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (506, 2) + inhomogeneous part.


    Aside from ignorance I am not sure where I am going wrong. Any ideas?

    Continue reading...

Compartilhe esta Página