mirror of
https://github.com/3b1b/manim.git
synced 2025-07-28 12:32:36 +08:00
Replacing apply_along_axis
This commit is contained in:
@ -54,7 +54,7 @@ class ParametricFunction(VMobject):
|
||||
full_t_range += list(np.linspace(s1, s2, n_inserts + 1)[1:])
|
||||
|
||||
points = np.array([self.function(t) for t in full_t_range])
|
||||
valid_indices = np.apply_along_axis(np.all, 1, np.isfinite(points))
|
||||
valid_indices = np.isfinite(points).all(1)
|
||||
points = points[valid_indices]
|
||||
if len(points) > 0:
|
||||
self.start_new_path(points[0])
|
||||
|
@ -298,7 +298,7 @@ class Mobject(Container):
|
||||
if len(kwargs) == 0:
|
||||
kwargs["about_point"] = ORIGIN
|
||||
self.apply_points_function_about_point(
|
||||
lambda points: np.apply_along_axis(function, 1, points),
|
||||
lambda points: np.array([function(p) for p in points]),
|
||||
**kwargs
|
||||
)
|
||||
return self
|
||||
@ -775,7 +775,7 @@ class Mobject(Container):
|
||||
return self.get_bounding_box_point(np.zeros(self.dim))
|
||||
|
||||
def get_center_of_mass(self):
|
||||
return np.apply_along_axis(np.mean, 0, self.get_all_points())
|
||||
return self.get_all_points().mean(0)
|
||||
|
||||
def get_boundary_point(self, direction):
|
||||
all_points = self.get_points_defining_boundary()
|
||||
|
@ -645,8 +645,8 @@ class VMobject(Mobject):
|
||||
for a in np.linspace(0, 1, n_sample_points)
|
||||
])
|
||||
diffs = points[1:] - points[:-1]
|
||||
norms = np.apply_along_axis(get_norm, 1, diffs)
|
||||
return np.sum(norms)
|
||||
norms = np.array([get_norm(d) for d in diffs])
|
||||
return norms.sum()
|
||||
|
||||
# Alignment
|
||||
def align_points(self, vmobject):
|
||||
|
@ -84,8 +84,7 @@ def interpolate_color(color1, color2, alpha):
|
||||
|
||||
def average_color(*colors):
|
||||
rgbs = np.array(list(map(color_to_rgb, colors)))
|
||||
mean_rgb = np.apply_along_axis(np.mean, 0, rgbs)
|
||||
return rgb_to_color(mean_rgb)
|
||||
return rgb_to_color(rgbs.mean(0))
|
||||
|
||||
|
||||
def random_bright_color():
|
||||
|
Reference in New Issue
Block a user