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. ])
usage of np.delete
Medical Data Visualizer AttributeError: 'numpy.ndarray' object has no attribute
python - AttributeError: 'numpy.ndarray' object has no attribute 'columns' - Stack Overflow
AttributeError: 'numpy.ndarray' object has no attribute 'pop'
Videos
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
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)
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!
Hello there.
I started doing manim a few weeks ago and, since there's no official documentation, I've been trying to replicate some of the scenes of 3b1b's old proyects. Specifically, I'm trying to replicate this animation ( https://www.youtube.com/watch?v=k7RM-ot2NWY at 0:37), but whenever I try to render the file, this error appears: "AttributeError: 'numpy.ndarray' object has no attribute 'move_to'".
I've already spend hours looking through the manimlib files but i can't make sense out of this.
Heres the code of the animation that I've got so far:
from manimlib.imports import *
class VectoresComoEscalares(VectorScene):
CONFIG = {
"axis_config": {
"stroke_color": WHITE,
"stroke_width": 2,
"stroke_opacity": 0.8,
},
"background_line_style": {"stroke_width": 2, "stroke_opacity": 0.5,},
"vcoords": ([3, 2]),
"vcolor": ORANGE,
}
def construct(self):
grid = NumberPlane(**self.CONFIG)
self.add(grid)
self.lock_in_faded_grid()
self.play(ShowCreation(grid), run_time=2)
self.wait()
kwargs = {
"stroke_width": 4,
}
vector = self.add_vector(self.vcoords, self.vcolor, **kwargs)
array, x_line, y_line = self.vector_to_coords(vector)
self.add(array)
self.wait()
new_array = self.ideas_generales_escalares(array, vector)
self.scale_basis_vectors(new_array)
self.show_symbolic_sum(new_array, vector)
def ideas_generales_escalares(self, array, vector):
startmo = self.get_mobjects()
txt = TextMobject(
"Vean cada coordenada como un escalar.", tex_to_color_map={"escalar": RED}
)
txt.to_edge(DOWN)
x, y = array.get_entries()
new_x = x.copy().scale(2).set_color(X_COLOR)
new_x.move_to(3 * LEFT + 2 * UP)
new_y = y.copy().scale(2).set_color(Y_COLOR)
new_y.move_to(3 * RIGHT + 2 * UP)
i_hat, j_hat = self.get_basis_vectors()
new_i_hat = Vector(self.vcoords[0] * i_hat.get_end(), color=X_COLOR)
new_j_hat = Vector(self.vcoords[1] * j_hat.get_end(), color=X_COLOR)
g1 = VGroup(i_hat, new_i_hat).shift(3 * LEFT)
g2 = VGroup(i_hat, new_j_hat).shift(3 * RIGHT)
new_array = Matrix([new_x.copy(), new_y.copy()])
new_array.scale(0.5)
new_array.shift(
-new_array.get_boundary_point(-vector.get_end()) + 1.1 * vector.get_end()
)
self.remove(*startmo)
self.play(Transform(x, new_x), Transform(y, new_y), Write(txt))
self.play(FadeIn(i_hat), FadeIn(j_hat))
self.wait()
self.play(FadeIn(i_hat), FadeIn(j_hat))
self.wait()
self.play(Transform(i_hat, new_i_hat), Transform(j_hat, new_j_hat), run_time=3)
self.wait()
startmo.remove(array)
new_x, new_y = new_array.get_entries()
self.play(
Transform(x, new_x),
Transform(y, new_y),
FadeOut(i_hat),
FadeOut(j_hat),
Write(new_array.get_brackets()),
FadeIn(VMobject(*startmo)),
FadeOut(txt),
)
self.remove(x, y)
self.add(new_array)
return new_array