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)
Videos
Hi,
I'm trying to create a numpy v-stack and creating 3 np.array's for it, by filling them with a loop:
I get the error: 'AttributeError: 'numpy.ndarray' object has no attribute 'np' . I think I'm using the wrong notation to append to the empty arrays:
neighbor_id = [id_ for id_ in range(1, n_obs) if id_ != user_id]
neighbor_id_arr = np.array(neighbor_id)
similarity = np.array([])
num_interactions = np.array([])
# get similarity and num_interactions
for id_ in neighbor_id:
similarity.np.append(np.dot(user_item.loc[user_id],user_item.loc[id_])) #The issue is here, I think
num_interactions.np.append(user_interactions.loc[id_])
c = numpy.vstack((neighbor_id_arr, similarity,num_interactions))
Thanks!
James
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'
It would be helpful if you could post the full stack trace, so that we can see which line your error occurs at. In general, the more information you can provide in a question, the better.
In this case, it looks like your full_model_pipeline may somehow become a numpy array. Since you have a one-element pipeline, you could try changing
full_model_pipeline = Pipeline(steps =[
('full_pipeline',full_pipeline),
('model',LinearRegression())
])
full_model_pipeline.fit(X_train,y_train)
to
model = LinearRegression()
model.fit(X_train, y_train)
I believe you need to add () where you add scaler to the pipeline: ('std_scaler',StandardScaler) --> ('std_scaler',StandardScaler())