adv_ex is already a numpy array, so you can’t call .numpy() again on it (which is a tensor method). Store adv_ex as a tensor or avoid calling numpy on it: adv_ex = perturbed_data.squeeze().detach().cpu() adv_examples.append( (init_pred.item(), final_pred.item(), adv_ex) ) Answer from ptrblck on discuss.pytorch.org
🌐
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

Python - AttributeError: 'numpy.ndarray' object has no attribute 'append' - Stack Overflow
This is related to my question, here. I now have the updated code as follows: import numpy as np import _pickle as cPickle from PIL import Image import sys,os pixels = [] labels = [] traindata =... More on stackoverflow.com
🌐 stackoverflow.com
python - Multivariate Regression Error “AttributeError: 'numpy.ndarray' object has no attribute 'columns'” - Data Science Stack Exchange
I'm trying to run a multivariate linear regression but I'm getting an error when trying to get the coefficients of the regression model. The error I'm getting is this: AttributeError: 'numpy.ndarray' More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
September 25, 2019
'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
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
Top answer
1 of 4
13

Numpy arrays do not have an append method. Use the Numpy append function instead:

import numpy as np

array_3 = np.append(array_1, array_2, axis=n)
# you can either specify an integer axis value n or remove the keyword argument completely

For example, if array_1 and array_2 have the following values:

array_1 = np.array([1, 2])
array_2 = np.array([3, 4])

If you call np.append without specifying an axis value, like so:

array_3 = np.append(array_1, array_2)

array_3 will have the following value:

array([1, 2, 3, 4])

Else, if you call np.append with an axis value of 0, like so:

array_3 = np.append(array_1, array_2, axis=0)

array_3 will have the following value:

 array([[1, 2],
        [3, 4]]) 

More information on the append function here: https://docs.scipy.org/doc/numpy/reference/generated/numpy.append.html

2 of 4
8
for root, dirs, files in os.walk(directory):
    for file in files:
        floc = file
        im = Image.open(str(directory) + '\\' + floc)
        pix = np.array(im.getdata())
        pixels.append(pix)
        labels.append(1)   # append(i)???

So far ok. But you want to leave pixels as a list until you are done with the iteration.

pixels = np.array(pixels)
labels = np.array(labels)

You had this indention right in your other question. What happened? previous

Iterating, collecting values in a list, and then at the end joining things into a bigger array is the right way. To make things clear I often prefer to use notation like:

alist = []
for ..
    alist.append(...)
arr = np.array(alist)

If names indicate something about the nature of the object I'm less likely to get errors like yours.

I don't understand what you are trying to do with traindata. I doubt if you need to build it during the loop. pixels and labels have the basic information.

That

traindata = np.array([traindata[i][i],traindata[1]], dtype=object)

comes from the previous question. I'm not sure you understand that answer.

traindata = []
traindata.append(pixels)
traindata.append(labels)

if done outside the loop is just

traindata = [pixels, labels]

labels is a 1d array, a bunch of 1s (or [0,1,2,3...] if my guess is right). pixels is a higher dimension array. What is its shape?

Stop right there. There's no point in turning that list into an array. You can save the list with pickle.

You are copying code from an earlier question, and getting the formatting wrong. cPickle very large amount of data

🌐
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
Find elsewhere
🌐
Neurostars
neurostars.org › community chat
AttributeError: 'numpy.ndarray' object has no attribute 'func' - Community Chat - Neurostars
September 1, 2022 - Hello, I am working on a subject on my local pc I did preprocessing through fmriprep on docker. I used the when I wanted to run import nibabel as nib from nibabel.testing import data_path import numpy as np from nilearn import datasets atlas = datasets.fetch_atlas_msdl() Loading atlas image stored in ‘maps’ atlas_filename = atlas[‘maps’] Loading atlas data stored in ‘labels’ labels = atlas[‘labels’] Load the functional datasets a = nib.load(’/home/roya/outputneww2/sub-1001/ses-01/...
🌐
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.
🌐
Edureka Community
edureka.co › home › community › categories › python › attributeerror type object numpy ndarray has...
AttributeError type object numpy ndarray has no attribute array function | Edureka Community
April 13, 2020 - Hi Guys, I installed numpy module in my system. But when I tried to import this module ... '__array_function__' How can I solve this error?
🌐
GitHub
github.com › aertslab › pySCENIC › issues › 350
AttributeError: 'numpy.ndarray' object has no attribute 'quantile' when doing nGenesDetectedPerCell.quantile() · Issue #350 · aertslab/pySCENIC
December 22, 2021 - AttributeError: 'numpy.ndarray' object has no attribute 'quantile' when doing nGenesDetectedPerCell.quantile()#350 ... Describe the bug A clear and concise description of what the bug is.
Author   hyjforesight
🌐
GitHub
github.com › ray-project › ray › issues › 17706
[rllib] "AttributeError: 'numpy.ndarray' object has no attribute 'items'" on certain turn-based MultiAgentEnvs with Dict obs space. · Issue #17706 · ray-project/ray
August 10, 2021 - [rllib] "AttributeError: 'numpy.ndarray' object has no attribute 'items'" on certain turn-based MultiAgentEnvs with Dict obs space.#17706
Author   akshaygh0sh
🌐
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 tutorial explains how to fix the following error in NumPy: 'numpy.ndarray' object has no attribute 'index'.
🌐
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...
🌐
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 is caused by using the append() method to add an item to a 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 - This tutorial explains how to fix the following error in NumPy: 'numpy.ndarray' object has no attribute 'append'
🌐
Edureka Community
edureka.co › home › community › categories › python › attributeerror numpy ndarray object has no...
AttributeError numpy ndarray object has no attribute append | Edureka Community
May 5, 2020 - Hi Guys, I am trying to append new dataset in my array using append function, but It is showing ... attribute 'append' How can I solve this error?
🌐
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