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
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: numpy.ndarray object has no attribute values
Attributeerror: numpy.ndarray object has no attribute values
July 12, 2026 - Most common cause: calling a method on None (NoneType has no attribute X). Other causes: typo in method name, wrong object type (str when you expected list), or using a feature removed in a newer library version.
Discussions

AttributeError: 'numpy.ndarray' object has no attribute 'numpy'
@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 ... More on discuss.pytorch.org
🌐 discuss.pytorch.org
12
0
April 9, 2019
python - AttributeError: 'numpy.ndarray' object has no attribute 'get' - Stack Overflow
As an aside, it is preferred to use pandas.DataFrames instead of numpy.arrays. The examples in the docs, which I assume you have tried to emulate here, use DataFrames. You can convert your array into a DataFrame, and specify the name of the variable you will later plot. More on stackoverflow.com
🌐 stackoverflow.com
tensorflow2.0 - 'numpy.ndarray' object has no attribute 'name' - Stack Overflow
After following this tutorial (https://www.tensorflow.org/tutorials/structured_data/feature_columns) I am trying to repeat it in Colab with my own data. I follow step by step but by the end, I reac... More on stackoverflow.com
🌐 stackoverflow.com
January 24, 2020
scikit learn - AttributeError: 'numpy.ndarray' object has no attribute 'columns' - Data Science Stack Exchange
import numpy as np import pandas as pd from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split from sklearn.feature_selection import SelectFromModel... More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
June 21, 2019
People also ask

How do I fix 'NoneType object has no attribute'?
The variable you're accessing is None, but you expected an object. Trace back to where it was assigned: a function returning None instead of an object (forgot to return), a database query returning no rows (Model.objects.first() returns None when empty), or an API call that failed silently. Safe pattern: if obj is not None: obj.method() OR use the walrus operator: if (obj := get_obj()): obj.method().
🌐
itsourcecode.com
itsourcecode.com › home › attributeerror: numpy.ndarray object has no attribute values
Attributeerror: numpy.ndarray object has no attribute values
What is Python AttributeError and what causes it?
AttributeError is raised when you access an attribute or method that doesn't exist on the object. Most common cause: calling a method on None (NoneType has no attribute X). Other causes: typo in method name, wrong object type (str when you expected list), or using a feature removed in a newer library version. The error names exactly which type and which missing attribute.
🌐
itsourcecode.com
itsourcecode.com › home › attributeerror: numpy.ndarray object has no attribute values
Attributeerror: numpy.ndarray object has no attribute values
How do I prevent AttributeError from None values?
Three patterns: (1) Always validate function returns (if result is None: raise). (2) Use type hints with Optional[X] to make None-ability explicit. (3) Use the walrus operator + early return: if (val := get_val()) is None: return default; use val. Defensive coding around None-able returns prevents 90% of AttributeError in production.
🌐
itsourcecode.com
itsourcecode.com › home › attributeerror: numpy.ndarray object has no attribute values
Attributeerror: numpy.ndarray object has no attribute values
🌐
GitHub
github.com › marcotcr › anchor › issues › 37
'numpy.ndarray' object has no attribute 'feature_names' · Issue #37 · marcotcr/anchor
November 29, 2019 - I get this error 'numpy.ndarray' object has no attribute 'feature_names' When trying to execute explainer = AnchorTabular(model.predict, feature_names=X_test.columns.values.tolist()) I tried to convert to numpy array, but that did not wo...
Author: marcotcr
🌐
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 ...
🌐
Pythoneo
pythoneo.com › how-to-resolve-attributeerror-numpy-ndarray-object-has-no-attribute-function_name
How to Fix AttributeError: 'numpy.ndarray' Has No Attribute (Complete Guide) - Pythoneo: Python Programming, Seaborn & Plotly Tutorials
December 5, 2025 - ⚡ Quick Answer: This error means NumPy array doesn’t have the attribute you’re calling. Common causes: 1) Using pandas methods on NumPy arrays (.values, .append), 2) Misspelling attribute names, 3) Forgetting parentheses on methods. Check object type with type(obj) to confirm it’s actually ...
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 59886124 › numpy-ndarray-object-has-no-attribute-name
tensorflow2.0 - 'numpy.ndarray' object has no attribute 'name' - Stack Overflow
January 24, 2020 - All the same, the likely distinction is that the shape of your data does not match the shape of the data in the tutorial. You may want to give that a check. ... ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) in Tensorflow
🌐
Reddit
reddit.com › r/learnpython › attribute error numpy.ndarray object has no attribute 'vectorize'
r/learnpython on Reddit: Attribute error numpy.ndarray object has no attribute 'vectorize'
September 15, 2019 -
Recoding Variables
"
#I need to recode variables given there are "5" responses present on a 4-point scale
scldict = {1:1,2:2,3:3,4:4,5:'NaN'}
w1array = np.array(week1)
w1vec = w1array.vectorize(scldict)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-92-e3f6056d2727> in <module>()
      2 scaldict = {1:1,2:2,3:3,4:4,5:'NaN'}
      3 w1array = np.array(week1)
----> 4 w1vec = w1array.vectorize(scaldict)

AttributeError: 'numpy.ndarray' object has no attribute 'vectorize'

Hello world, I am trying to recode variables given there are invalid responses in my survey data. I am using a dictionary and the vectorize function (seen on StackOverflow) to do this. Why is the vectorize function not available? I am lost.

Any help or suggestions for recoding variables in an efficient manner would be appreciated.

🌐
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 17, 2020 - this is my part of a code , whey it shows :AttributeError: 'numpy.ndarray' object has no attribute ' ... np.array(prets) pvols = np.array(pvols)
Top answer
1 of 1
7

The immediate cause of your problem is that dataset1 and dataset2 are ndarray type, with dtype == object.

Although your values are read in as float type, when you access the column of the values array you return (at the line dataset1 = data1[:,ithattr1]), the dtype is changed to object (as you are actually pulling the data row by row, then extracting a column and numpy has both floats and strings in the row, so has to coerce to the most specific common data type - object).

You can get around this several ways. One is simply to make the arrays into lists, at which point Python coerces what looks like a float to be a float, i.e. change

ax.boxplot([dataset1,dataset2])

to

ax.boxplot([list(dataset1),list(dataset2)])

Another is to add lines explicitly setting the type:

dataset1 = dataset1.astype(np.float)
dataset2 = dataset2.astype(np.float)

This is a gotcha when you access pandas dataframes or numpy arrays containing different data types in columns by index. It's pretty hard to debug (took me a while to get it for this question and I've seen it before - see the edit history)


However, the way you're handling your data via numerical indices also means you end up having to reorder your columns etc for convenience in your loadData function. A better way would be to let pandas do all the heavy lifting on types etc...

As an example - I've put your code into what (I think) is a more conventional pandas / python writing. It's a bit shorter and doesn't require the hack to change the data to a list that I give you above. Code is below and output plot after that (using the input data snippet from your question)

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

def loadData(filename,cols):
    data = pd.read_csv(filename, quotechar='"',names=cols,header=None)
    return data

def boxplot(filename,cols):
    data1 = loadData(filename,cols)

    fig = plt.figure()
    ax = fig.add_subplot(111)

    ax.boxplot([data1['high'],data1['close/last']])
    plt.show()

cols=['date','close/last','volume','open','high','low']
filename = 'microsoft.csv'

boxplot(filename,cols)

Output

🌐
Itsourcecode
itsourcecode.com › home › [fixed 2026] attributeerror: module numpy has no attribute ndarray — solution
[Fixed 2026] AttributeError: Module Numpy Has No Attribute Ndarray — Solution
July 12, 2026 - Most common cause: calling a method on None (NoneType has no attribute X). Other causes: typo in method name, wrong object type (str when you expected list), or using a feature removed in a newer library version.
🌐
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.
🌐
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
Answer: The error is exactly what it says on the tin: NumPy’s ndarray object has no attribute [code ]append[/code] defined in its API. The error in question, for reference. We can start by asking, what is a numpy.ndarray? NumPy is an incredibly useful library for data manipulation in Python, wh...
🌐
GitHub
github.com › catalyst-team › catalyst › issues › 638
AttributeError: 'numpy.ndarray' object has no attribute 'items' when using `MulticlassDiceMetricCallback` · Issue #638 · catalyst-team/catalyst
February 6, 2020 - Describe the bug In the on_loader_end method for MulticlassDiceMetricCallback, batch_metrics is a numpy array instead of a dict. This is because batch_metrics = calculate_dice(...) and calculate_dice returns a np.ndarray of the dice coef...
Author: catalyst-team
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
Medical Data Visualizer AttributeError: 'numpy.ndarray' object has no attribute - Curriculum Help - The freeCodeCamp Forum
May 12, 2023 - 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 (test_module.CatPlotTestCase) Traceback (most recent call last): File “/home/runner/boilerplate-medical-data-visualizer/test_module.py”, line 26, in test_bar_plot_number_of_bars actual = len([rect fo...