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] the code does not give the results what I want using equal sign in python

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

  1. Stack

    Stack Membro Participativo

    I have code like this:

    import numpy as np
    a = np.zeros(shape = (4,4))
    a+= 2
    b = np.zeros(shape = (4,4))
    b+=2
    t = 0
    while t<2:
    for i in range(1,3):
    for j in range(1,3):
    if a[i,j] == a[i-1,j]:
    b[i,j] = a[i,j]+1
    print(a,t)
    print(b,t)
    a = b
    t+= 1


    I am hoping that at t = 2 a = [2 2 2 2, 2 3 3 2, 2 3 3 2, 2 2 2 2] and b = [2 2 2 2, 2 3 3 2, 2 4 4 2, 2 2 2 2] but in fact at the end of the run the a = [2 2 2 2, 2 3 3 2, 2 4 4 2, 2 2 2 2]

    Anyone know why? Is it because I am declaring a = b? If it is, is there any way to do it?

    Continue reading...

Compartilhe esta Página