From 24d3ba8680a23aad54ece035a49ee002cc79c3b3 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 4 Feb 2020 15:24:40 -0800 Subject: [PATCH] Added join_structured_arrays --- manimlib/utils/iterables.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/manimlib/utils/iterables.py b/manimlib/utils/iterables.py index 1cd26ed9..885af620 100644 --- a/manimlib/utils/iterables.py +++ b/manimlib/utils/iterables.py @@ -56,9 +56,8 @@ def batch_by_property(items, property_func): def add_batch_prop_pair(batch): if len(batch) > 0: - batch_prop_pairs.append( - (batch, property_func(batch[0])) - ) + prop = property_func(batch[0]) + batch_prop_pairs.append((batch, prop)) curr_batch = [] curr_prop = None for item in items: @@ -115,6 +114,21 @@ def remove_nones(sequence): return [x for x in sequence if x] +def join_structured_arrays(*arrays): + assert(len(arrays) > 0) + + result = np.zeros( + sum([len(arr) for arr in arrays]), + dtype=arrays[0].dtype + ) + lh = 0 + for array in arrays: + rh = lh + len(array) + result[lh:rh] = array + lh = rh + return result + + # Note this is redundant with it.chain