{"id":31296730,"url":"https://github.com/hansalemaos/cythoncartesian2","last_synced_at":"2026-05-17T15:43:28.333Z","repository":{"id":212169966,"uuid":"730868439","full_name":"hansalemaos/cythoncartesian2","owner":"hansalemaos","description":"Cartesian Product for NumPy - 40x faster than NumPy + itertools.product","archived":false,"fork":false,"pushed_at":"2023-12-12T21:14:26.000Z","size":23,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-08T21:55:08.622Z","etag":null,"topics":["algorithm","cartesian","cartesian-product","cython","fast","numpy"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/cythoncartesian2","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hansalemaos.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-12T21:13:38.000Z","updated_at":"2023-12-19T11:04:05.000Z","dependencies_parsed_at":"2023-12-12T22:27:24.000Z","dependency_job_id":"2ae6aae1-d2f3-4c17-a022-79614457dabf","html_url":"https://github.com/hansalemaos/cythoncartesian2","commit_stats":null,"previous_names":["hansalemaos/cythoncartesian2"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hansalemaos/cythoncartesian2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythoncartesian2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythoncartesian2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythoncartesian2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythoncartesian2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hansalemaos","download_url":"https://codeload.github.com/hansalemaos/cythoncartesian2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythoncartesian2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276540062,"owners_count":25660349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","cartesian","cartesian-product","cython","fast","numpy"],"created_at":"2025-09-24T21:03:09.707Z","updated_at":"2025-09-24T21:03:29.473Z","avatar_url":"https://github.com/hansalemaos.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cartesian Product for NumPy - 40x faster than NumPy + itertools.product \r\n\r\n## pip install cythoncartesian2\r\n\r\n### Tested against Windows / Python 3.11 / Anaconda\r\n\r\n## Cython (and a C/C++ compiler) must be installed\r\n\r\n\r\n\r\n\r\n```python\r\n\r\ncartesian_product(*args, outputdtype=np.uint32, dtype=np.uint32):\r\n    Calculate the Cartesian product of input arrays.\r\n\r\n    Parameters:\r\n    - *args: Variable number of input arrays.\r\n    - outputdtype (numpy.dtype): Data type of the output array.\r\n    - dtype (numpy.dtype): Data type used for intermediate calculations. # be careful!\r\n\r\n    Returns:\r\n    - numpy.ndarray: Cartesian product of input arrays.\r\n\r\n\t\r\nimport random\r\nfrom cythoncartesian2 import cartesian_product\r\nimport numpy as np\r\n\r\n# Strings are NOT supported!\r\n\r\nargs=[[h*random.uniform(1,4) for h in (range(random.randint(2,9)))] for x in range(9)]\r\nq=cartesian_product(*args,outputdtype=np.float32,dtype=np.uint32)\r\n\r\n# array([[0.       , 0.       , 0.       , ..., 0.       , 0.       ,\r\n#         0.       ],\r\n#        [3.529998 , 0.       , 0.       , ..., 0.       , 0.       ,\r\n#         0.       ],\r\n#        [0.       , 3.715651 , 0.       , ..., 0.       , 0.       ,\r\n#         0.       ],\r\n#        ...,\r\n#        [3.529998 , 7.956308 , 5.9014587, ..., 1.0379078, 7.9018135,\r\n#         8.816498 ],\r\n#        [0.       , 9.456019 , 5.9014587, ..., 1.0379078, 7.9018135,\r\n#         8.816498 ],\r\n#        [3.529998 , 9.456019 , 5.9014587, ..., 1.0379078, 7.9018135,\r\n#         8.816498 ]], dtype=float32)\r\n\r\nargs=[[h for h in (range(8))] for x in range(9)]\r\nq=cartesian_product(*args,outputdtype=np.uint8,dtype=np.uint32)\r\n\r\n# %timeit q=cartesian_product(*args,outputdtype=np.uint8,dtype=np.uint32)\r\n# 1.63 s ± 36.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\r\n\r\n# %timeit (list(itertools.product(*args)))\r\n# 11.3 s ± 180 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\r\n\r\n# %timeit q=np.array(list(itertools.product(*args)),dtype=np.uint8)\r\n# 1min 6s ± 282 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\r\n\r\n# q\r\n# Out[3]:\r\n# array([[0, 0, 0, ..., 0, 0, 0],\r\n#        [1, 0, 0, ..., 0, 0, 0],\r\n#        [2, 0, 0, ..., 0, 0, 0],\r\n#        ...,\r\n#        [5, 7, 7, ..., 7, 7, 7],\r\n#        [6, 7, 7, ..., 7, 7, 7],\r\n#        [7, 7, 7, ..., 7, 7, 7]], dtype=uint8)\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Fcythoncartesian2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhansalemaos%2Fcythoncartesian2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Fcythoncartesian2/lists"}