1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Confused about the `copy` attribution of `numpy.astype`

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

  1. Stack

    Stack Membro Participativo

    I am confused about the copy attribution of numpy.astype. I check out the material in a link; it said:


    By default, astype always returns a newly allocated array. If this is set to false, and the dtype, order, and subok requirements are satisfied, the input array is returned instead of a copy.
    ​

    Does it mean that it will change the original value of a ndarray object?

    Like:

    x = np.array([1, 2, 2.5])
    x.astype(int, copy=False)


    But it seems that x still is the original value array([ 1., 2., 2.5]).

    What is the explanation?

    Continue reading...

Compartilhe esta Página