mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Added join_structured_arrays
This commit is contained in:
parent
13b69a14d8
commit
24d3ba8680
1 changed files with 17 additions and 3 deletions
|
@ -56,9 +56,8 @@ def batch_by_property(items, property_func):
|
||||||
|
|
||||||
def add_batch_prop_pair(batch):
|
def add_batch_prop_pair(batch):
|
||||||
if len(batch) > 0:
|
if len(batch) > 0:
|
||||||
batch_prop_pairs.append(
|
prop = property_func(batch[0])
|
||||||
(batch, property_func(batch[0]))
|
batch_prop_pairs.append((batch, prop))
|
||||||
)
|
|
||||||
curr_batch = []
|
curr_batch = []
|
||||||
curr_prop = None
|
curr_prop = None
|
||||||
for item in items:
|
for item in items:
|
||||||
|
@ -115,6 +114,21 @@ def remove_nones(sequence):
|
||||||
return [x for x in sequence if x]
|
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
|
# Note this is redundant with it.chain
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue