Although numpy.ndarray has a mean, max, std etc. method, it does not have a median method. For a list of all methods available for an ndarray, see the numpy documentation for ndarray.
It is available as a function that takes the array as an argument:
>>> import numpy as np
>>> a = np.array([1,2,3,4,5,6,7,8,9,10])
>>> np.median(a)
5.5
As you will see in the documentation for ndarray.mean, ndarray.mean and np.mean are "equivalent functions," so this is just a matter of semantics.
AttributeError: 'numpy.ndarray' object has no attribute 'numpy'
mean() (and median()) should work with "object" arrays
python - How to get the median in numpy? - Stack Overflow
Error creating numpy v-stack, 'AttributeError: 'numpy.ndarray' object has no attribute 'np'
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
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())