Use numpy.concatenate(list1 , list2) or numpy.append()
Look into the thread at Concatenate a NumPy array to another NumPy array.
Answer from Arpita Biswas on Stack OverflowUse numpy.concatenate(list1 , list2) or numpy.append()
Look into the thread at Concatenate a NumPy array to another NumPy array.
Basically, numpy arrays don't have have access to append(). If we look into documentation, we need to use np.append(array), where array is the values to be appended.
import numpy as np
arr = np.array([1,2,3,47,1,0,2])
np.append(arr, 4)
Week 2 Exercise 6 "'numpy.ndarray' object has no attribute 'append'"
AttributeError: 'numpy.ndarray' object has no attribute 'extend'
AttributeError: 'numpy.ndarray' object has no attribute 'numpy'
AttributeError with numpy array in NEAT algorithm for OpenAI Gym integration
Videos
I need help. This is the code which gives error:
import numpy as np
num = 3
X_new = np.array([])
for i in range(1, num+1):
print('Enter the', i, '. data:')
n = float(input())
X_new.append(n)
print('\n', X_new)
And this is the error:
AttributeError: 'numpy.ndarray' object has no attribute 'append'
>>> import numpy as np
>>> a = np.array([1, 2, 3])
>>> b = np.array([5, 6, 7])
>>> np.vstack(a, b)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: vstack() takes exactly 1 argument (2 given)
>>>
>>> np.vstack((a, b))
array([[1, 2, 3],
[5, 6, 7]])
vstack is a numpy function which takes only a single argument in the form of a tuple . You need to call it and assign the output to your variable. So instead of
g.vstack((temp_g,g))
use
g=np.vstack((temp_g,g))