if you need to flatten you can directly use flatten() on numpy.ndarray object
X = X.flatten()
Link to doc: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.flatten.html
Answer from Talha Tayyab on Stack OverflowAttributeError: 'numpy.ndarray' object has no attribute 'cpu'
'numpy.ndarray' object has no attribute 'numpy'.
python - Unable to Create Polynomial Features for regression using numpy.plyfit -- AttributeError: 'numpy.ndarray' object has no attribute 'to_numpy' - Stack Overflow
Error creating numpy v-stack, 'AttributeError: 'numpy.ndarray' object has no attribute 'np'
Videos
if you need to flatten you can directly use flatten() on numpy.ndarray object
X = X.flatten()
Link to doc: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.flatten.html
DO NOT VOTE UP RESPONSE MAIN WORK DONE BY @wayne above:
Did you run print(type(X)) on X prior to that line that gave an error? Given you got an error of AttributeError: 'numpy.ndarray' object has no attribute 'to_numpy', X appears to already be numpy object. Also, I don't think the to_numpy comes from numpy. Pandas has one. Polars has one. This drops us in the end of the problem and so we cannot provide much help without more code upstream.
solution
reload data set.
df = pd.read_csv(file_name, header=0)
[str(i) for i in ([["CPU_frequency"]])]
code above resolves.
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
Probably you created a numpy array named time somewhere before this code snippet. You should not do that, because the module time now gets overwritten. Rename your array (to something like time_list), and it works.
I have similar question like this. The error occurs as below
'numpy.ndarray' object has no attribute 'asctime'
That means you have created an array named 'time', so in order to avoid the conficts between Keywords and Variables etc.We have to identify every variable's name and be cautious when import xx as xx