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
🌐
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

Discussions

scikit learn - AttributeError: 'numpy.ndarray' object has no attribute 'fit' - Data Science Stack Exchange
I am relatively new to ML and in the process of learning pipelines. I am creating a pipeline of custom transformers and get this error: AttributeError: 'numpy.ndarray' object has no attribute 'fit'. More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
September 24, 2021
Medical Data Visualizer AttributeError: 'numpy.ndarray' object has no attribute
I completed the project on google colab and everything seems to be working once I copy it over to replit. The charts seem to look good. However, I’m getting the following 2 errors on test: ====================================================================== ERROR: test_bar_plot_number_of_bars ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
May 11, 2023
pandas - 'numpy.ndarray' object has no attribute 'plot' - Data Science Stack Exchange
I am trying to balance my data set and using imblearn library for this but After performing fit operation when i try to see the data count in dependent variable its showing me below error Attribute... More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
March 29, 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
🌐
Career Karma
careerkarma.com › blog › python › python attributeerror: ‘numpy.ndarray’ object has no attribute ‘append’ solution
Python AttributeError: 'numpy.ndarray' object has no attribute 'append' Solution
December 1, 2023 - The AttributeError: ‘numpy.ndarray’ object has no attribute ‘append’ error indicates you are using the regular Python append() method to add an item to a NumPy array. Instead, you should use the numpy.append() method, which uses the ...
Find elsewhere
🌐
Statology
statology.org › home › how to fix: ‘numpy.ndarray’ object has no attribute ‘index’
How to Fix: 'numpy.ndarray' object has no attribute 'index'
September 17, 2021 - This error occurs when you attempt to use the index() function on a NumPy array, which does not have an index attribute available to use.
🌐
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.
🌐
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
🌐
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.
🌐
Statology
statology.org › home › how to fix: ‘numpy.ndarray’ object has no attribute ‘append’
How to Fix: 'numpy.ndarray' object has no attribute 'append'
August 4, 2021 - AttributeError: 'numpy.ndarray' object has no attribute 'append' This error occurs when you attempt to append one or more values to the end of a NumPy array by using the append() function in regular Python.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-fix-numpy-ndarray-object-has-no-attribute-append
How to Fix: ‘numpy.ndarray’ object has no attribute ‘append’ - GeeksforGeeks
November 28, 2021 - As in the output, we can see that initially, the NumPy array had 4 items (1, 2, 3, 4). After appending 5 to the list, it is reflected in the NumPy array. This is so because here the append function is used on NumPy and not on NumPy array object (numpy.ndarray).
🌐
GitHub
github.com › oegedijk › explainerdashboard › issues › 95
AttributeError: 'numpy.ndarray' object has no attribute 'columns' · Issue #95 · oegedijk/explainerdashboard
March 3, 2021 - AttributeError: 'numpy.ndarray' object has no attribute 'columns'#95 · Copy link · apavlo89 · opened · on Mar 3, 2021 · Issue body actions · This looks amazing but I can't run it on my dataset.
Author   apavlo89
🌐
GitHub
github.com › openvinotoolkit › anomalib › issues › 2452
[Bug]: AttributeError: 'numpy.ndarray' object has no attribute 'to' · Issue #2452 · open-edge-platform/anomalib
December 5, 2024 - [Bug]: AttributeError: 'numpy.ndarray' object has no attribute 'to'#2452 · Copy link · Septembit · opened · on Dec 5, 2024 · Issue body actions · Seems this bug still exists when I use torch inferencer in anomalib 1.2.0 Do anyone have a way to solve it?
Author   Septembit
🌐
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 def main(): RANDOM_SEED = 8927 rng = numpy.random.default_rng(RANDOM_SEED) N = 10000 mu_actual = numpy.array([1.0, -2.0]) sigmas_actual = numpy.array([0.7, 1.5]) Rho_actual ...
🌐
Python Forum
python-forum.io › thread-37639.html
AttributeError: 'numpy.ndarray' object has no attribute 'load'
I have the following error: Error: currrent_pixel = my_image.load() AttributeError: 'numpy.ndarray' object has no attribute 'load'in the following code: import cv2 import numpy as np my_image = cv2.imread...