Skip to content

Commit

Permalink
Remove usage of np.append
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Feb 13, 2020
1 parent c780a74 commit c654ca4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion manimlib/mobject/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ class Vector(Arrow):

def __init__(self, direction=RIGHT, **kwargs):
if len(direction) == 2:
direction = np.append(np.array(direction), 0)
direction = np.hstack([direction, 0])
Arrow.__init__(self, ORIGIN, direction, **kwargs)


Expand Down
5 changes: 1 addition & 4 deletions manimlib/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,7 @@ def repeat(self, count):
This can make transition animations nicer
"""
def repeat_array(array):
return reduce(
lambda a1, a2: np.append(a1, a2, axis=0),
[array] * count
)
return np.vstack([array] * count)
for mob in self.family_members_with_points():
mob.apply_over_attr_arrays(repeat_array)
return self
Expand Down
4 changes: 2 additions & 2 deletions manimlib/mobject/types/point_cloud_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def add_points(self, points, rgbas=None, color=None, alpha=1):
if not isinstance(points, np.ndarray):
points = np.array(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:
color = Color(color) if color else self.color
rgbas = np.repeat(
Expand All @@ -37,7 +37,7 @@ def add_points(self, points, rgbas=None, color=None, alpha=1):
)
elif len(rgbas) != len(points):
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

def set_color(self, color=YELLOW_C, family=True):
Expand Down
2 changes: 1 addition & 1 deletion manimlib/utils/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def color_to_int_rgb(color):

def color_to_int_rgba(color, opacity=1.0):
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):
Expand Down
6 changes: 3 additions & 3 deletions manimlib/utils/space_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def quaternion_mult(q1, q2):


def quaternion_from_angle_axis(angle, axis):
return np.append(
return np.hstack([
np.cos(angle / 2),
np.sin(angle / 2) * normalize(axis)
)
])


def angle_axis_from_quaternion(quaternion):
Expand Down Expand Up @@ -65,7 +65,7 @@ def rotate_vector(vector, angle, axis=OUT):
quat_inv = quaternion_conjugate(quat)
product = reduce(
quaternion_mult,
[quat, np.append(0, vector), quat_inv]
[quat, np.hstack([0, vector]), quat_inv]
)
return product[1:]
else:
Expand Down

0 comments on commit c654ca4

Please sign in to comment.