iterables¶
该部分代码来自 3b1b/manim,有待重构
- janim.utils.iterables.flatten(iterable)¶
- janim.utils.iterables.remove_list_redundancies(lst: Iterable[T]) list[T]¶
Used instead of list(set(l)) to maintain order Keeps the last occurrence of each element
- janim.utils.iterables.list_update(l1: Iterable[T], l2: Iterable[T]) list[T]¶
Used instead of list(set(l1).update(l2)) to maintain order, making sure duplicates are removed from l1, not l2.
- janim.utils.iterables.list_difference_update(l1: Iterable[T], l2: Iterable[T]) list[T]¶
- janim.utils.iterables.adjacent_n_tuples(objects: Iterable[T], n: int) zip[tuple[T, T]]¶
- janim.utils.iterables.adjacent_pairs(objects: Iterable[T]) zip[tuple[T, T]]¶
- janim.utils.iterables.batch_by_property(items: Iterable[T], property_func: Callable[[T], S]) list[tuple[T, S]]¶
Takes in a list, and returns a list of tuples, (batch, prop) such that all items in a batch have the same output when put into property_func, and such that chaining all these batches together would give the original list (i.e. order is preserved)
- janim.utils.iterables.listify(obj) list¶
- janim.utils.iterables.resize_array(nparray: ndarray, length: int) ndarray¶
- janim.utils.iterables.resize_preserving_order(array: ndarray, length: int) ndarray¶
- janim.utils.iterables.resize_preserving_order(array: list[T], length: int, fall_back: Callable = types.NoneType) list[T]
- janim.utils.iterables.resize_preserving_order_indice_groups(len1: int, len2: int) list[list[int]]¶
- janim.utils.iterables.resize_preserving_head_and_tail(array: ndarray, length: int)¶
- janim.utils.iterables.resize_and_repeatedly_extend(array: ~numpy.ndarray, length: int, fall_back: ~typing.Callable[[int], ~numpy.ndarray] = <function <lambda>>) ndarray¶
注意:这个函数在 length <= len(array) 时,不会产生 array 的拷贝
- janim.utils.iterables.resize_with_interpolation(nparray: ndarray, length: int) ndarray¶
- janim.utils.iterables.make_even(iterable_1: Sequence[T], iterable_2: Sequence[S]) tuple[list[T], list[S]]¶
- janim.utils.iterables.hash_obj(obj: object) int¶