It would be nice to see your train_generator code for clarity, but it does not seem to be a torch DataLoader. In this case, you should probably convert your arrays to tensors manually. There are several ways to do so:

  • torch.from_numpy(numpy_array) - for numpy arrays;
  • torch.as_tensor(list) - for common lists and tuples;
  • torch.tensor(array) should also work but the above ways will avoid copying the data when possible.
Answer from dx2-66 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

'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 - AttributeError: 'numpy.ndarray' object has no attribute 'to' - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
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
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
🌐
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 › 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
🌐
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
Find elsewhere
🌐
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.
🌐
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

🌐
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 ...
🌐
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 - Off | 00000000:03:00.0 Off | 0 | | N/A 53C P0 42W / 250W | 1862MiB / 32510MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 10481 C ...nda3/envs/cuml/bin/python 923MiB | | 0 N/A N/A 10546 C ...nda3/envs/cuml/bin/python 935MiB | +------------------------------------------------------------
Author   aamirshafi
🌐
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
🌐
GeeksforGeeks
geeksforgeeks.org › 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.
🌐
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
🌐
Quora
quora.com › Why-do-I-get-numpy-ndarray-object-has-no-attribute-append-error
Why do I get “numpy.ndarray object has no attribute append error”? - Quora
This error occurs because numpy.ndarray objects do not implement the list method append — numpy arrays have a fixed size and their API differs from Python lists. Calling arr.append(...) raises AttributeError.
🌐
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).