mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 21:44:19 +08:00
Add cartesian_product
This commit is contained in:
@ -136,6 +136,18 @@ def array_is_constant(arr: np.ndarray) -> bool:
|
||||
return len(arr) > 0 and (arr == arr[0]).all()
|
||||
|
||||
|
||||
def cartesian_product(*arrays: np.ndarray):
|
||||
"""
|
||||
Copied from https://stackoverflow.com/a/11146645
|
||||
"""
|
||||
la = len(arrays)
|
||||
dtype = np.result_type(*arrays)
|
||||
arr = np.empty([len(a) for a in arrays] + [la], dtype=dtype)
|
||||
for i, a in enumerate(np.ix_(*arrays)):
|
||||
arr[..., i] = a
|
||||
return arr.reshape(-1, la)
|
||||
|
||||
|
||||
def hash_obj(obj: object) -> int:
|
||||
if isinstance(obj, dict):
|
||||
return hash(tuple(sorted([
|
||||
|
Reference in New Issue
Block a user