I think I've figured it out.
The .remove() method is a list method, not an ndarray method.
So by using array.tolist() I can then apply the .remove() method and get the required result.
I think I've figured it out.
The .remove() method is a list method, not an ndarray method.
So by using array.tolist() I can then apply the .remove() method and get the required result.
This does not directly address your question, as worded, but instead condenses some of the points made in the other answers/comments.
The following demonstrates how to, effectively, remove the value 0.0 from a NumPy array.
>>> import numpy as np
>>> arr = np.array([0.1, 0.2, 0.0, 1.0, 0.0]) # NOTE: Works if more than one value == 0.0
>>> arr
array([0.1, 0.2, 0. , 1. , 0. ])
>>> indices = np.where(arr==0.0)
>>> arr = np.delete(arr, indices)
>>> arr
array([0.1, 0.2, 1. ])
Another useful method is numpy.unique(), which, "Returns the sorted unique elements of an array.":
>>> import numpy as np
>>> arr = np.array([0.1, 0.2, 0.0, 1.0, 0.0])
>>> arr = np.unique(arr)
>>> arr
array([0. , 0.1, 0.2, 1. ])
python - 'numpy.ndarray' object has no attribute 'delete' - Stack Overflow
python - AttributeError: 'numpy.ndarray' object has no attribute 'columns' - Stack Overflow
scikit learn - AttributeError: 'numpy.ndarray' object has no attribute 'columns' - Data Science Stack Exchange
AttributeError: 'numpy.ndarray' object has no attribute 'pop'
Videos
Check the Pandas documentation, but I think
X_train = df_train.drop(['ID','TARGET'], axis=1).values
.values returns a numpy array, not a Pandas dataframe. An array does not have a columns attribute.
remove_features_identical - if you pass this an array, make sure you are only using array, not dataframe, features. Otherwise, make sure you pass it a dataframe. And don't use variable names like DataFrame.
Maybe this solution solve such problem, try this:
X_train = pd.DataFrame(X_train, columns = X.columns)
X_test = pd.DataFrame(X_test, columns=X.columns)
The problem is that train_test_split(X, y, ...) returns numpy arrays and not pandas dataframes. Numpy arrays have no attribute named columns
If you want to see what features SelectFromModel kept, you need to substitute X_train (which is a numpy.array) with X which is a pandas.DataFrame.
selected_feat= X.columns[(sel.get_support())]
This will return a list of the columns kept by the feature selector.
If you wanted to see how many features were kept you can just run this:
sel.get_support().sum() # by default this will count 'True' as 1 and 'False' as 0
because this :
X = df.iloc[:,:24481].values
y = df.iloc[:, -1].values
you should remove .values or make extra X_col, y_col like that
X_col = df.iloc[:,:24481]
y_col = df.iloc[:, -1]
Write a function to calculate accumulated GPA (omit grade <5).
def gpa_of_pass(marks, credits):
gpa_list=[]
for i in range(len(marks)):
for j in range(len(marks[i])):
if marks[i][j] < 5:
marks=marks[i].pop(j)
for i in marks:
for j in i:
gpa_list.append(np.dot(i,credits)/sum(credits))
return gpa_list
marks = np.array([
[8.0, 9.0, 10.0],
[4.0, 9.0, 8.0],
[8.0, 3.0, 8.0],
[10.0, 9.0, 5.0],
[9.0, 9.0, 4.0]
])
credits = np.array([2, 2, 1])
gpa_of_pass(marks, credits)I ran a for loop to remove the grade <5 before calculating the GPA but I got the error in the title. Would you please have any suggestions? Thank you so much!
Using .values on a pandas dataframe gives you a numpy array. This will not contain column names and such. You do this when setting X like this:
X = dataset[['Read?', 'x1', .. ,'x47']].values
But then you try to get the column names from X (which it does not have) by writing X.columns here:
coeff_df = pd.DataFrame(regressor.coef_, X.columns, columns=['Coefficient'])
So store your column names in a variable or input them again, like this:
coeff_df = pd.DataFrame(regressor.coef_, ['Read?', 'x1', .. ,'x47'], columns=['Coefficient'])
hi remove values method
X = dataset[['Read?', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6' , 'x7','x8','x9','x10','x11','x12','x13','x14','x15','x16','x17','x18','x19','x20','x21','x22','x23','x24','x25','x26','x27','x28','x29','x30','x31','x32','x33','x34','x35','x36','x37','x38','x39','x40','x41','x42','x43','x44','x45','x46','x47']]
coeff_df = pd.DataFrame(regressor.coef_, X.columns, columns=['Coefficient'])
Hey lads n gals
I am working on an assignment, where we are doing a grading system for students on the -3 to 12 scale...
here is the code so far:
import numpy as np
from RoundGrade import roundGrade
def computeFinalGrade(grades):
if -3 in grades:
return -3
if len(grades)==1:
return grades[0]
if len(grades)>=2:
grademin=grades.delete(min(grades))
average=np.mean(grademin)
return roundGrade(average)
grades=np.array([6,9,2,5,2])
print(computeFinalGrade(grades))
however this gives me the error messege:
'numpy.ndarray' object has no attribute 'delete'
i have tried converting the array to a list, but it doesn't help
thanks <3