AttributeError: 'numpy.ndarray' object has no attribute 'append'

后端 未结 2 1851
借酒劲吻你
借酒劲吻你 2021-02-04 23:54

I am trying to run the code presented on the second page:

http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-an

相关标签:
2条回答
  • 2021-02-05 00:12

    Use numpy.concatenate(list1 , list2) or numpy.append() Look into the thread at Append a NumPy array to a NumPy array.

    0 讨论(0)
  • 2021-02-05 00:15

    I got this error after change a loop in my program, let`s see:

    for ...
      for ... 
         x_batch.append(one_hot(int_word, vocab_size))
         y_batch.append(one_hot(int_nb, vocab_size, value))
      ...
      ...
      if ...
            x_batch = np.asarray(x_batch)
            y_batch = np.asarray(y_batch)
    ...
    

    In fact, I was reusing the variable and forgot to reset them inside the external loop, like the comment of John Lyon:

    for ...
      x_batch = []
      y_batch = []
      for ... 
         x_batch.append(one_hot(int_word, vocab_size))
         y_batch.append(one_hot(int_nb, vocab_size, value))
      ...
      ...
      if ...
            x_batch = np.asarray(x_batch)
            y_batch = np.asarray(y_batch)
    ...
    

    Then, check if you are using np.asarray() or something like that.

    0 讨论(0)
提交回复
热议问题