FuncAnimation matrix proceeds only one simulationHow to copy a dictionary and only edit the copyNumpy matrix to arraynumpy matrix vector multiplicationMatplotlib FuncAnimation not animating line plotMatplotlib FuncAnimation for scatter plotPython FuncAnimation is saved only 30%FuncAnimation not iterableFuncAnimation with a matrixSlow FuncAnimation ScriptFuncAnimation printing first image only

Is it possible to change original filename of an exe?

Why does the 6502 have the BIT instruction?

Employer demanding to see degree after poor code review

Do firearms count as ranged weapons?

File globbing pattern, !(*example), behaves differently in bash script than it does in bash shell

How do Russian speakers idiomatically express the idea of "Ce n’est pas donné à tout le monde de ..." in French?

How does apt-get work, in detail?

Is this story about US tax office reasonable?

Why do Russians call their women expensive ("дорогая")?

Is a post-climate apocolypse city in which many or most insects have disappeared realistic?

Windows 10 Programs start without visual Interface

Plot exactly N bounce of a ball

How to properly maintain eye contact with people that have distinct facial features?

What are the benefits of cryosleep?

What does the behaviour of water on the skin of an aircraft in flight tell us?

Split polygon using another polygon in QGIS

Preserving culinary oils

1960s sci-fi novella with a character who is treated as invisible by being ignored

How to extract lower and upper bound in numeric format from a confidence interval string?

What does uniform continuity mean exactly?

Should I use n only, b only, bg, bgn, or gn?

What is the difference between nullifying your vote and not going to vote at all?

What does "Marchentalender" on the front of a postcard mean?

Is there any use case for the bottom type as a function parameter type?



FuncAnimation matrix proceeds only one simulation


How to copy a dictionary and only edit the copyNumpy matrix to arraynumpy matrix vector multiplicationMatplotlib FuncAnimation not animating line plotMatplotlib FuncAnimation for scatter plotPython FuncAnimation is saved only 30%FuncAnimation not iterableFuncAnimation with a matrixSlow FuncAnimation ScriptFuncAnimation printing first image only






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to animate cellular automaton. PyCharm doesn't raise any errors or warnings (after some fights); however, I cannot force the program to proceed simulation more than once.



import numpy as np
from matplotlib import pyplot as plt
import matplotlib.animation as anim

s = np.array([[1,1,1], [1,10,1], [1,1,1]], dtype=np.int8) #Matrix of wages
e = np.zeros((19,), dtype=np.int8) # Vector of rules
e[3]=1
e[12]=1
e[13]=1

ma = np.array([[1, 0, 1], [0, 1, 0], [0, 1, 0], [0, 1, 0], [1, 0, 1], [1, 0, 0], [0, 0, 0]], dtype=np.int8) #The matrix to be tested

def cnt(num): #Enables counting - equal to frames
if num < 2:
return num
else:
return num + cnt(num-1)

def simulation(frame): #Simulation on a given matrix
count = cnt(8) - frame

n, m = ma.shape
p = np.zeros((n+2, m+2), dtype=np.int8) #Creates an extended matrix, avoiding conflicts at the edges of the initial matrix. Here I construct a torus
p[1:-1, 1:-1] = ma #middle
p[0, 1:-1] = ma[n-1] #the first row of p, the last of ma
p[-1, 1:-1] = ma[0] #the last row of p, the first of ma
p[1:-1, 0] = ma[0:, -1] #left col p, right of ma
p[1:-1, -1] = ma[0:, 0] #right col of p, left of ma
p[-1, 0] = ma[0, -1] #left bottom corner
p[-1, -1] = ma[0, 0] #right bottom corner
p[0, 0] = ma[-1, -1] #left upper corner
p[0, -1] = ma[-1, 0] #right upper corner

new = np.zeros(ma.shape, dtype=np.int8) #matrix to be updated

v, c = p.shape #verses and columns

if count:
for i in range(1, v):
for j in range(1, c):
if p[i-1:i+2, j-1:j+2].shape == (3, 3):
new[i-1, j-1] = e[np.sum(p[i-1:i+2,j-1:j+2]*s)]
plot.set_data(new)
#plt.axes().imshow(new)#.set_array(new) #I have given up this solution - it required adding axes
plt.title("Cellular automaton")
return plot

fig = plt.figure()
plot = plt.imshow(ma)

def init():
plot.set_data(ma)
plt.title("Cellular automaton")
return plot

#fig, ax = plt.subplots() # I have given up this, too

ani = anim.FuncAnimation(fig, simulation, frames = 8, init_func = init, interval = 500, repeat = False)
plt.show()


It shows only init and the first simulation. Supposedly, I have messed something up in displaying part (plot.set_data(new) etc.), but I don't have any idea which part needs to be corrected.



The first silution and the problem



I have changed new to ma and it seems to work at the moment. However, the state of the matrix depends on the already changed rows. How can I force the program to run calculations based on the initial matrix?










share|improve this question






























    0















    I am trying to animate cellular automaton. PyCharm doesn't raise any errors or warnings (after some fights); however, I cannot force the program to proceed simulation more than once.



    import numpy as np
    from matplotlib import pyplot as plt
    import matplotlib.animation as anim

    s = np.array([[1,1,1], [1,10,1], [1,1,1]], dtype=np.int8) #Matrix of wages
    e = np.zeros((19,), dtype=np.int8) # Vector of rules
    e[3]=1
    e[12]=1
    e[13]=1

    ma = np.array([[1, 0, 1], [0, 1, 0], [0, 1, 0], [0, 1, 0], [1, 0, 1], [1, 0, 0], [0, 0, 0]], dtype=np.int8) #The matrix to be tested

    def cnt(num): #Enables counting - equal to frames
    if num < 2:
    return num
    else:
    return num + cnt(num-1)

    def simulation(frame): #Simulation on a given matrix
    count = cnt(8) - frame

    n, m = ma.shape
    p = np.zeros((n+2, m+2), dtype=np.int8) #Creates an extended matrix, avoiding conflicts at the edges of the initial matrix. Here I construct a torus
    p[1:-1, 1:-1] = ma #middle
    p[0, 1:-1] = ma[n-1] #the first row of p, the last of ma
    p[-1, 1:-1] = ma[0] #the last row of p, the first of ma
    p[1:-1, 0] = ma[0:, -1] #left col p, right of ma
    p[1:-1, -1] = ma[0:, 0] #right col of p, left of ma
    p[-1, 0] = ma[0, -1] #left bottom corner
    p[-1, -1] = ma[0, 0] #right bottom corner
    p[0, 0] = ma[-1, -1] #left upper corner
    p[0, -1] = ma[-1, 0] #right upper corner

    new = np.zeros(ma.shape, dtype=np.int8) #matrix to be updated

    v, c = p.shape #verses and columns

    if count:
    for i in range(1, v):
    for j in range(1, c):
    if p[i-1:i+2, j-1:j+2].shape == (3, 3):
    new[i-1, j-1] = e[np.sum(p[i-1:i+2,j-1:j+2]*s)]
    plot.set_data(new)
    #plt.axes().imshow(new)#.set_array(new) #I have given up this solution - it required adding axes
    plt.title("Cellular automaton")
    return plot

    fig = plt.figure()
    plot = plt.imshow(ma)

    def init():
    plot.set_data(ma)
    plt.title("Cellular automaton")
    return plot

    #fig, ax = plt.subplots() # I have given up this, too

    ani = anim.FuncAnimation(fig, simulation, frames = 8, init_func = init, interval = 500, repeat = False)
    plt.show()


    It shows only init and the first simulation. Supposedly, I have messed something up in displaying part (plot.set_data(new) etc.), but I don't have any idea which part needs to be corrected.



    The first silution and the problem



    I have changed new to ma and it seems to work at the moment. However, the state of the matrix depends on the already changed rows. How can I force the program to run calculations based on the initial matrix?










    share|improve this question


























      0












      0








      0








      I am trying to animate cellular automaton. PyCharm doesn't raise any errors or warnings (after some fights); however, I cannot force the program to proceed simulation more than once.



      import numpy as np
      from matplotlib import pyplot as plt
      import matplotlib.animation as anim

      s = np.array([[1,1,1], [1,10,1], [1,1,1]], dtype=np.int8) #Matrix of wages
      e = np.zeros((19,), dtype=np.int8) # Vector of rules
      e[3]=1
      e[12]=1
      e[13]=1

      ma = np.array([[1, 0, 1], [0, 1, 0], [0, 1, 0], [0, 1, 0], [1, 0, 1], [1, 0, 0], [0, 0, 0]], dtype=np.int8) #The matrix to be tested

      def cnt(num): #Enables counting - equal to frames
      if num < 2:
      return num
      else:
      return num + cnt(num-1)

      def simulation(frame): #Simulation on a given matrix
      count = cnt(8) - frame

      n, m = ma.shape
      p = np.zeros((n+2, m+2), dtype=np.int8) #Creates an extended matrix, avoiding conflicts at the edges of the initial matrix. Here I construct a torus
      p[1:-1, 1:-1] = ma #middle
      p[0, 1:-1] = ma[n-1] #the first row of p, the last of ma
      p[-1, 1:-1] = ma[0] #the last row of p, the first of ma
      p[1:-1, 0] = ma[0:, -1] #left col p, right of ma
      p[1:-1, -1] = ma[0:, 0] #right col of p, left of ma
      p[-1, 0] = ma[0, -1] #left bottom corner
      p[-1, -1] = ma[0, 0] #right bottom corner
      p[0, 0] = ma[-1, -1] #left upper corner
      p[0, -1] = ma[-1, 0] #right upper corner

      new = np.zeros(ma.shape, dtype=np.int8) #matrix to be updated

      v, c = p.shape #verses and columns

      if count:
      for i in range(1, v):
      for j in range(1, c):
      if p[i-1:i+2, j-1:j+2].shape == (3, 3):
      new[i-1, j-1] = e[np.sum(p[i-1:i+2,j-1:j+2]*s)]
      plot.set_data(new)
      #plt.axes().imshow(new)#.set_array(new) #I have given up this solution - it required adding axes
      plt.title("Cellular automaton")
      return plot

      fig = plt.figure()
      plot = plt.imshow(ma)

      def init():
      plot.set_data(ma)
      plt.title("Cellular automaton")
      return plot

      #fig, ax = plt.subplots() # I have given up this, too

      ani = anim.FuncAnimation(fig, simulation, frames = 8, init_func = init, interval = 500, repeat = False)
      plt.show()


      It shows only init and the first simulation. Supposedly, I have messed something up in displaying part (plot.set_data(new) etc.), but I don't have any idea which part needs to be corrected.



      The first silution and the problem



      I have changed new to ma and it seems to work at the moment. However, the state of the matrix depends on the already changed rows. How can I force the program to run calculations based on the initial matrix?










      share|improve this question
















      I am trying to animate cellular automaton. PyCharm doesn't raise any errors or warnings (after some fights); however, I cannot force the program to proceed simulation more than once.



      import numpy as np
      from matplotlib import pyplot as plt
      import matplotlib.animation as anim

      s = np.array([[1,1,1], [1,10,1], [1,1,1]], dtype=np.int8) #Matrix of wages
      e = np.zeros((19,), dtype=np.int8) # Vector of rules
      e[3]=1
      e[12]=1
      e[13]=1

      ma = np.array([[1, 0, 1], [0, 1, 0], [0, 1, 0], [0, 1, 0], [1, 0, 1], [1, 0, 0], [0, 0, 0]], dtype=np.int8) #The matrix to be tested

      def cnt(num): #Enables counting - equal to frames
      if num < 2:
      return num
      else:
      return num + cnt(num-1)

      def simulation(frame): #Simulation on a given matrix
      count = cnt(8) - frame

      n, m = ma.shape
      p = np.zeros((n+2, m+2), dtype=np.int8) #Creates an extended matrix, avoiding conflicts at the edges of the initial matrix. Here I construct a torus
      p[1:-1, 1:-1] = ma #middle
      p[0, 1:-1] = ma[n-1] #the first row of p, the last of ma
      p[-1, 1:-1] = ma[0] #the last row of p, the first of ma
      p[1:-1, 0] = ma[0:, -1] #left col p, right of ma
      p[1:-1, -1] = ma[0:, 0] #right col of p, left of ma
      p[-1, 0] = ma[0, -1] #left bottom corner
      p[-1, -1] = ma[0, 0] #right bottom corner
      p[0, 0] = ma[-1, -1] #left upper corner
      p[0, -1] = ma[-1, 0] #right upper corner

      new = np.zeros(ma.shape, dtype=np.int8) #matrix to be updated

      v, c = p.shape #verses and columns

      if count:
      for i in range(1, v):
      for j in range(1, c):
      if p[i-1:i+2, j-1:j+2].shape == (3, 3):
      new[i-1, j-1] = e[np.sum(p[i-1:i+2,j-1:j+2]*s)]
      plot.set_data(new)
      #plt.axes().imshow(new)#.set_array(new) #I have given up this solution - it required adding axes
      plt.title("Cellular automaton")
      return plot

      fig = plt.figure()
      plot = plt.imshow(ma)

      def init():
      plot.set_data(ma)
      plt.title("Cellular automaton")
      return plot

      #fig, ax = plt.subplots() # I have given up this, too

      ani = anim.FuncAnimation(fig, simulation, frames = 8, init_func = init, interval = 500, repeat = False)
      plt.show()


      It shows only init and the first simulation. Supposedly, I have messed something up in displaying part (plot.set_data(new) etc.), but I don't have any idea which part needs to be corrected.



      The first silution and the problem



      I have changed new to ma and it seems to work at the moment. However, the state of the matrix depends on the already changed rows. How can I force the program to run calculations based on the initial matrix?







      python-3.x numpy matplotlib animation matrix






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 9:26







      fgh

















      asked Mar 24 at 8:46









      fghfgh

      358




      358






















          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322048%2ffuncanimation-matrix-proceeds-only-one-simulation%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322048%2ffuncanimation-matrix-proceeds-only-one-simulation%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현