Numpy Won't Append Arrays
I'm currently working on a neural network to play Rock-Paper-Scissors, but I've run into an enormous issue. I'm having the neural network predict what will happen next based on a h
Solution 1:
As the docs says,
Values are appended to a copy of this array.
(emphasis mine).
So np.append
creates a new list instead of modification of your original one. You have to write:
input_data = np.append(input_data, current_turn, axis = 0)
Example:
import numpy as np
my_array = np.array([1, 2, 3])
print(my_array)
# [1 2 3]
my_array = np.append(my_array, [4])
print(my_array)
# [1 2 3 4]
See also this question if are interested why np.append
behaves in such a way.
Solution 2:
You can use numpy.concatenate method instead.
import numpy as np
arr = np.array([1, 2])
arr = np.concatenate((arr,[4]))
print(arr)
# [1 2 3 4]
see docs for more help: http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.concatenate.html
Post a Comment for "Numpy Won't Append Arrays"