[Python] When did numpy change the behavior of A = B[slice]?

Discussão em 'Python' iniciado por Stack, Setembro 5, 2025.

  1. Stack

    Stack Membro Participativo

    I know that if I have a numpy array A, then a statement like B = A will make a "shallow" copy, i.e., B will point to the same memory address as A. However, before some numpy version, B = A[slice] used to create a new array B such that changing B did not change A. I know this because I have code that depends on this behavior that used to work. However, in numpy 1.24.3, if I do

    A = numpy.array([1,2,3,4,])
    B = A[2:4]
    B[0] = -1


    then A[2] changes to -1. Does anyone know when this behavior changed? Or have I really not run that code (the one I know expected this behavior and used to work) for a very long time?

    Continue reading...

Compartilhe esta Página