Remove usage of np.append

This commit is contained in:
Grant Sanderson
2020-02-13 12:03:54 -08:00
parent c780a7471b
commit c654ca4506
5 changed files with 8 additions and 11 deletions

View File

@ -653,7 +653,7 @@ class Vector(Arrow):
def __init__(self, direction=RIGHT, **kwargs): def __init__(self, direction=RIGHT, **kwargs):
if len(direction) == 2: if len(direction) == 2:
direction = np.append(np.array(direction), 0) direction = np.hstack([direction, 0])
Arrow.__init__(self, ORIGIN, direction, **kwargs) Arrow.__init__(self, ORIGIN, direction, **kwargs)

View File

@ -346,10 +346,7 @@ class Mobject(Container):
This can make transition animations nicer This can make transition animations nicer
""" """
def repeat_array(array): def repeat_array(array):
return reduce( return np.vstack([array] * count)
lambda a1, a2: np.append(a1, a2, axis=0),
[array] * count
)
for mob in self.family_members_with_points(): for mob in self.family_members_with_points():
mob.apply_over_attr_arrays(repeat_array) mob.apply_over_attr_arrays(repeat_array)
return self return self

View File

@ -27,7 +27,7 @@ class PMobject(Mobject):
if not isinstance(points, np.ndarray): if not isinstance(points, np.ndarray):
points = np.array(points) points = np.array(points)
num_new_points = len(points) num_new_points = len(points)
self.points = np.append(self.points, points, axis=0) self.points = np.vstack([self.points, points])
if rgbas is None: if rgbas is None:
color = Color(color) if color else self.color color = Color(color) if color else self.color
rgbas = np.repeat( rgbas = np.repeat(
@ -37,7 +37,7 @@ class PMobject(Mobject):
) )
elif len(rgbas) != len(points): elif len(rgbas) != len(points):
raise Exception("points and rgbas must have same shape") raise Exception("points and rgbas must have same shape")
self.rgbas = np.append(self.rgbas, rgbas, axis=0) self.rgbas = np.vstack([self.rgbas, rgbas])
return self return self
def set_color(self, color=YELLOW_C, family=True): def set_color(self, color=YELLOW_C, family=True):

View File

@ -58,7 +58,7 @@ def color_to_int_rgb(color):
def color_to_int_rgba(color, opacity=1.0): def color_to_int_rgba(color, opacity=1.0):
alpha = int(255 * opacity) alpha = int(255 * opacity)
return np.append(color_to_int_rgb(color), alpha) return np.array([*color_to_int_rgb(color), alpha])
def color_gradient(reference_colors, length_of_output): def color_gradient(reference_colors, length_of_output):

View File

@ -31,10 +31,10 @@ def quaternion_mult(q1, q2):
def quaternion_from_angle_axis(angle, axis): def quaternion_from_angle_axis(angle, axis):
return np.append( return np.hstack([
np.cos(angle / 2), np.cos(angle / 2),
np.sin(angle / 2) * normalize(axis) np.sin(angle / 2) * normalize(axis)
) ])
def angle_axis_from_quaternion(quaternion): def angle_axis_from_quaternion(quaternion):
@ -65,7 +65,7 @@ def rotate_vector(vector, angle, axis=OUT):
quat_inv = quaternion_conjugate(quat) quat_inv = quaternion_conjugate(quat)
product = reduce( product = reduce(
quaternion_mult, quaternion_mult,
[quat, np.append(0, vector), quat_inv] [quat, np.hstack([0, vector]), quat_inv]
) )
return product[1:] return product[1:]
else: else: