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 Overflow
🌐
PyTorch Forums
discuss.pytorch.org › t › how-to-fix-attributeerror-numpy-ndarray-object-has-no-attribute-cpu › 158960
How to fix: "AttributeError: 'numpy.ndarray' object has no attribute 'cpu'" - PyTorch Forums
August 11, 2022 - Hi All I have data from a dataloader which I get a data and corresponding label from it. I am trying to normalize the labels within a certain range using T.tonumpy_denormalize , however I get this error AttributeError: 'numpy.ndarray' object has no attribute 'cpu'.
🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-numpy-ndarray-object-has-no-attribute-cpu › 79512
AttributeError: 'numpy.ndarray' object has no attribute 'cpu' - PyTorch Forums
May 3, 2020 - Hi, I am having a problem in plotting the accuracy of trained model, I adopted the following code for plotting the accuracy from tutorial Finetuning Torchvision Models — PyTorch Tutorials 2.2.0+cu121 documentation. Here is the code, ohist = [] shist = [] ohist = [h.cpu().numpy() for h in epoch_accuracy_o] shist = [h.cpu().numpy() for h in epoch_accuracy_s] print(ohist) print(shist) plt.title("Validation Accuracy vs.
Discussions

AttributeError: 'numpy.ndarray' object has no attribute 'cpu'
There was an error while loading. Please reload this page · Need some help in solving this issue while running "feature_extractor" I get this error: More on github.com
🌐 github.com
3
August 30, 2020
'numpy.ndarray' object has no attribute 'numpy'.
I tried to submit this to the repository linked in your publication, but, apparently, I can't! I received this error while running predictions: Traceback (most recent call last): File "/Us... More on github.com
🌐 github.com
1
November 16, 2023
python - Unable to Create Polynomial Features for regression using numpy.plyfit -- AttributeError: 'numpy.ndarray' object has no attribute 'to_numpy' - Stack Overflow
Excuse my ignorance I have never used polynomial regression with numpy before. I am attempting to use the variable "CPU_frequency" to create Polynomial features. Using three different val... More on stackoverflow.com
🌐 stackoverflow.com
Error creating numpy v-stack, 'AttributeError: 'numpy.ndarray' object has no attribute 'np'
I think I'm using the wrong notation to append to the empty arrays: The best way to find out is to read the documentation https://numpy.org/doc/stable/reference/generated/numpy.append.html And yes you are. Numpy arrays don't have an append method, it's a function from the library. And there is no such thing as object.library.function(...) which is what you are doing here similarity.np.append(...) num_interactions.np.append(...) It should be similarity = np.append(similarity, values_to_append) num_interactions = np.append(num_interactions, values_to_append) And should avoid appending data to a numpy array. I'm almost sure there is much better alternative. But since you didn't explain what you are trying to do, I can't help you with that. More on reddit.com
🌐 r/learnpython
5
2
May 4, 2021
🌐
GitHub
github.com › atomistic-machine-learning › schnetpack › issues › 328
Tutorial 2: 'numpy.ndarray' object has no attribute 'cpu' · Issue #328 · atomistic-machine-learning/schnetpack
September 7, 2021 - Keys: ['_atomic_numbers', '_positions', '_neighbors', '_cell', '_cell_offset', '_atom_mask', '_neighbor_mask'] Traceback (most recent call last): File "tutorial_02_qm9_nn.py", line 294, in <module> print("Truth:", props[QM9.U0].cpu().numpy()[0]) AttributeError: 'numpy.ndarray' object has no attribute 'cpu' Does anyone know what might be wrong?
Author   hejops
🌐
GitHub
github.com › ekosman › AnomalyDetectionCVPR2018-Pytorch › issues › 28
AttributeError: 'numpy.ndarray' object has no attribute 'cpu' · Issue #28 · ekosman/AnomalyDetectionCVPR2018-Pytorch
August 30, 2020 - 36 for i, (dir, vid_name, start_frame) in enumerate(zip(dirs, vid_names, sampled_idx.cpu().numpy())): 37 dir = path.join(save_dir, dir) ---> 38 features_writer.write(feature=outputs[i], video_name=vid_name, idx=start_frame, dir=dir) 39 40 features_writer.dump() <ipython-input-7-563b8b257603> in write(self, feature, video_name, idx, dir) 48 self._init_video(video_name, dir) 49 ---> 50 self.store(feature, idx) <ipython-input-7-563b8b257603> in store(self, feature, idx) 38 39 def store(self, feature, idx): ---> 40 self.data[idx] = list(feature.cpu().numpy()) 41 42 def write(self, feature, video_name, idx, dir): AttributeError: 'numpy.ndarray' object has no attribute 'cpu' Anyone facing the same issue?
Author   NitinDatta8
🌐
GitHub
github.com › waylandy › phosformer › issues › 1
'numpy.ndarray' object has no attribute 'numpy'. · Issue #1 · waylandy/phosformer
November 16, 2023 - Traceback (most recent call last): File "/Users/joshuasacher/phosformer/wip1_S234.py", line 17, in <module> predictions = Phosformer.predict_many( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/joshuasacher/phosformer/Phosformer/modules.py", line 204, in predict_many return np.array([i['pred'] for i in batch_job(kinases, peptides, **kwargs)]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/joshuasacher/phosformer/Phosformer/modules.py", line 204, in <listcomp> return np.array([i['pred'] for i in batch_job(kinases, peptides, **kwargs)]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/joshuasacher/phosformer/Phosformer/modules.py", line 96, in batch_job pred = softmax(result['logits'].cpu(), axis=1)[:,1].numpy() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'numpy.ndarray' object has no attribute 'numpy'.
Author   jrsacher
🌐
Csdn
ask.csdn.net › questions › 7961887
AttributeError: 'numpy.ndarray' object has no attribute 'cpu'_编程语言-CSDN问答
如果您手头有 PyTorch 张量,需要将这些张量转移到 CPU 上时,则可以使用 Tensor.cpu() 方法。 · 本回答被题主选为最佳回答 , 对您是否有帮助呢? 本回答被专家选为最佳回答 , 对您是否有帮助呢? 本回答被题主和专家选为最佳回答 , 对您是否有帮助呢? ... 【NumPy】成功解决AttributeError: ‘numpy.ndarray‘ object has no attribute ‘median‘ 2024-04-20 23:23 · 高斯小哥的博客 解锁NumPy宝藏,告别`AttributeError`! 还在为`numpy.ndarray`对象没有`median`属性而头疼吗?来,带你一探究竟!本文将深入浅出地解析`np.median()`函数的使用,助你轻松掌握其正确姿势。 我们将一起探讨NumPy...
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › error creating numpy v-stack, 'attributeerror: 'numpy.ndarray' object has no attribute 'np'
r/learnpython on Reddit: Error creating numpy v-stack, 'AttributeError: 'numpy.ndarray' object has no attribute 'np'
May 4, 2021 -

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

🌐
Fast.ai
forums.fast.ai › fastai › fastai dev
AttributeError: 'memoryview' object has no attribute 'cpu' and RuntimeError: number of dims don't match in permute - fastai dev - fast.ai Course Forums
October 6, 2018 - Just wanted to help anybody else that runs into this issue when working with show_image in the new fastai library. I had a few issues. The first thing I ran into was AttributeError: 'memoryview' object has no attribute 'cpu'. This was because I was trying to put a numpy.ndarray into show_image which expects a tensor.
🌐
PyTorch Forums
discuss.pytorch.org › vision
AttributeError: 'numpy.ndarray' object has no attribute 'numpy' - vision - PyTorch Forums
April 9, 2019 - @ptrblck, Hi! I’m trying to visualize the adversarial images generated by this script: https://pytorch.org/tutorials/beginner/fgsm_tutorial.html This tutorial is used for the mnist data. Now I want to use for other data which is trained using the inception_v1 architecture, below is the gist ...
🌐
GitHub
github.com › ClementPinard › FlowNetPytorch › issues › 51
AttributeError: 'numpy.ndarray' object has no attribute 'detach' · Issue #51 · ClementPinard/FlowNetPytorch
November 12, 2018 - Use nn.functional.interpolate instead.") Exception KeyError: KeyError(<weakref at 0x7f097f5b3f18; to 'tqdm' at 0x7f097f5a9590>,) in <bound method tqdm.del of 0%| | 0/1 [00:05<?, ?it/s]> ignored Traceback (most recent call last): File "run_inference.py", line 93, in main() File "/home/maria/anaconda2/lib/python2.7/site-packages/torch/autograd/grad_mode.py", line 46, in decorate_no_grad return func(*args, **kwargs) File "run_inference.py", line 87, in main rgb_flow = flow2rgb(args.div_flow * flow_output.numpy(), max_value=args.max_flow) File "/media/maria/0C7ED7537ED733E4/Downloads-/inspiration_code/FlowNetPytorch-master/main.py", line 340, in flow2rgb flow_map_np = flow_map.detach().cpu().numpy() AttributeError: 'numpy.ndarray' object has no attribute 'detach' Reactions are currently unavailable ·
Author   maria-ito
🌐
GitHub
github.com › DSE-MSU › DeepRobust › issues › 85
AttributeError: 'numpy.ndarray' object has no attribute 'tolil' · Issue #85 · DSE-MSU/DeepRobust
November 1, 2021 - Traceback (most recent call last): File "/home/wanghuijuan/whj_code2/aisafety/try2.py", line 20, in <module> model.attack(features, adj, labels, target_node, n_perturbations=5) File "/home/wanghuijuan/anaconda3/envs/cuda102/lib/python3.9/site-packages/deeprobust/graph/targeted_attack/nettack.py", line 150, in attack self.ori_features = features.tolil() AttributeError: 'numpy.ndarray' object has no attribute 'tolil'
Author   PolarisRisingWar
🌐
Google Groups
groups.google.com › g › deap-users › c › alxeOILteJk
AttributeError: 'numpy.ndarray' object has no attribute 'fitness'
Yes, you must change your individual type from list to numpy.ndarray (that would be the same thing if you would like to inherit from, say, array.array).
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-numpy-ndarray-object-has-no-attribute-index
How to Fix: ‘numpy.ndarray’ object has no attribute ‘index’ - GeeksforGeeks
November 28, 2021 - ‘numpy.ndarray’ object has no attribute ‘index’ is an attribute error which indicates that there is no index method or attribute available to use in Numpy array.
🌐
PyMC Discourse
discourse.pymc.io › questions › v5
AttributeError: 'numpy.ndarray' object has no attribute 'at' when sampling LKJ Cholesky Covariance Priors for Multivariate Normal Models example with numpyro or blackjax - v5 - PyMC Discourse
February 26, 2025 - I wanted to try out sampling with numpyro on an AMD GPU using a model based on this example: https://www.pymc.io/projects/examples/en/latest/howto/LKJ.html It works with PyMC and nutpie samplers, but not with jax samplers. The code I run looks like the following: import pymc as pm import numpy ...
🌐
GitHub
github.com › rapidsai › cuml › issues › 2952
[QST] Error ('numpy.ndarray' object has no attribute 'to_pandas') while running MNMG Kmeans Demo Notebook · Issue #2952 · rapidsai/cuml
October 11, 2020 - [QST] Error ('numpy.ndarray' object has no attribute 'to_pandas') while running MNMG Kmeans Demo Notebook#2952
Author   aamirshafi
🌐
GitHub
github.com › Ecogenomics › GTDBTk › issues › 644
AttributeError: 'numpy.ndarray' object has no attribute 'tostring' in GTDB-Tk v2.4.1 with Python 3.13 and numpy >=1.24 · Issue #644 · Ecogenomics/GTDBTk
June 20, 2025 - AttributeError: 'numpy.ndarray' object lacks the attribute 'tostring' The deprecation of the tostring() method in numpy versions 1.24 and up, which was replaced by tobytes(), appears to be the cause of this error.
Author   kursatozer
🌐
Streamlit
discuss.streamlit.io › community cloud
While predict we are getting error AttributeError: 'numpy.ndarray' object has no attribute 'predict' - Community Cloud - Streamlit
April 2, 2024 - Github link : git@github.com:pawaravinash0007/MachineLearning.git streamlit deployment link : Streamlit Dear All, We are getting attribute errors AttributeError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded ...