{"id":15043589,"url":"https://github.com/hansalemaos/cythonnestednumpy","last_synced_at":"2026-01-07T06:08:25.022Z","repository":{"id":211610477,"uuid":"729595389","full_name":"hansalemaos/cythonnestednumpy","owner":"hansalemaos","description":"performs sorting and grouping operations on multidimensional NumPy arrays using Cython and hash-based algorithms.","archived":false,"fork":false,"pushed_at":"2023-12-09T18:16:05.000Z","size":102,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T20:07:35.871Z","etag":null,"topics":["cython","hash","numpy","sorting"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/cythonnestednumpy/","language":"C","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-09T18:15:42.000Z","updated_at":"2023-12-19T11:04:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"c73f145c-decb-401c-a941-50be2819d7d7","html_url":"https://github.com/hansalemaos/cythonnestednumpy","commit_stats":null,"previous_names":["hansalemaos/cythonnestednumpy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythonnestednumpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythonnestednumpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythonnestednumpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythonnestednumpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hansalemaos","download_url":"https://codeload.github.com/hansalemaos/cythonnestednumpy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245858884,"owners_count":20684062,"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","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":["cython","hash","numpy","sorting"],"created_at":"2024-09-24T20:49:18.731Z","updated_at":"2026-01-07T06:08:24.982Z","avatar_url":"https://github.com/hansalemaos.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# performs sorting and grouping operations on multidimensional NumPy arrays using Cython and hash-based algorithms.\r\n\r\n\r\n## pip install cythonnestednumpy\r\n\r\n### Tested against Windows / Python 3.11 / Anaconda\r\n\r\n\r\n## Cython (and a C/C++ compiler) must be installed\r\n\r\n\r\n\r\n```python\r\nimport numpy as np\r\nfrom cythonnestednumpy import HashSort\r\n\r\nimg1 = np.full([900,1800,3],255,dtype=np.uint8)\r\nimg2 = np.full([900,1800,3],255,dtype=np.uint8)\r\nimg2[...,0]=0\r\nimg3 = np.full([900,1800,3],255,dtype=np.uint8)\r\nimg3[...,2]=1\r\na=np.concatenate([img1,img2,img3])\r\ncyne=HashSort(a,unordered=True)\r\n# 1st column: absolut index (using a.flatten() or a.ravel())\r\n# 2nd - n column: dimension (the more dimensions your array has, the more columns will show up)\r\n# 3rd column: The index in cyne.iterray\r\n# 4th column: 1 is for the first item (unique) found. 0 means that there has been found the same value before.\r\n# 5th column: How many matches\r\n# 6th column: Hashcode\r\n\r\n\r\ncyne.generate_hash_array(last_dim=None)\r\nresultdata=cyne.sort_by_absolut_index(ascending=True)\r\n# Out[3]:\r\n# array([[                   0,                    0,                    1,                    1,  2497830064280488930],\r\n#        [                  30,                    1,                    0,                    2,  2497830064280488930],\r\n#        [                  60,                    2,                    0,                    3,  2497830064280488930],\r\n#        [                  90,                    3,                    0,                    4,  2497830064280488930],\r\n# ...\r\n#        [                 780,                   26,                    0,                    7, -5024405870974420794],\r\n#        [                 810,                   27,                    0,                    8, -5024405870974420794],\r\n#        [                 840,                   28,                    0,                    9, -5024405870974420794],\r\n#        [                 870,                   29,                    0,                   10, -5024405870974420794]], dtype=int64)\r\ncyne.sort_by_absolut_index(ascending=False)\r\n\r\n# Out[4]:\r\n# array([[                 870,                   29,                    0,                   10, -5024405870974420794],\r\n#        [                 840,                   28,                    0,                    9, -5024405870974420794],\r\n#        [                 810,                   27,                    0,                    8, -5024405870974420794],\r\n#        [                 780,                   26,                    0,                    7, -5024405870974420794],\r\n#        [                 750,                   25,                    0,                    6, -5024405870974420794],\r\n#        [                 720,                   24,                    0,                    5, -5024405870974420794],\r\n# ...\r\n#        [                 240,                    8,                    0,                    9,  2497830064280488930],\r\n#        [                 210,                    7,                    0,                    8,  2497830064280488930],\r\n#        [                 180,                    6,                    0,                    7,  2497830064280488930],\r\n#        [                 150,                    5,                    0,                    6,  2497830064280488930],\r\n#        [                 120,                    4,                    0,                    5,  2497830064280488930],\r\n#        [                  90,                    3,                    0,                    4,  2497830064280488930],\r\n#        [                  60,                    2,                    0,                    3,  2497830064280488930],\r\n#        [                  30,                    1,                    0,                    2,  2497830064280488930],\r\n#        [                   0,                    0,                    1,                    1,  2497830064280488930]], dtype=int64)\r\n\r\n\r\ncyne.get_unique_dims_data()\r\n# Out[3]:\r\n# [array([255, 255, 255], dtype=uint8),\r\n#  array([255, 255, 255], dtype=uint8),\r\n#  array([255, 255, 255], dtype=uint8)]\r\n\r\ncyne.get_unique_dims_data(start_dim=2,end_dim=-1)\r\n#          [255, 255, 255],\r\n#          [255, 255, 255],\r\n#          [255, 255, 255],\r\n#          [255, 255, 255],\r\n#          [255, 255, 255]],\r\n#\r\n#         [[255, 255, 255],\r\n#          [255, 255, 255],\r\n#           ...\r\n#          [  0, 255, 255]],\r\n#\r\n#         [[  0, 255, 255],\r\n#          [  0, 255, 255],\r\n#          [  0, 255, 255],\r\n#          [  0, 255, 255],\r\n#          [  0, 255, 255],\r\n#          [  0, 255, 255],\r\n#          [  0, 255, 255],\r\n#          [  0, 255, 255],\r\n#          [  0, 255, 255],\r\n#          [  0, 255, 255]],\r\n\r\ncyne.get_all_values(start_dim=0,end_dim=-1)\r\n#         ...,\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255]],\r\n#        ...,\r\n#        [[255, 255,   1],\r\n#         [255, 255,   1],\r\n#         [255, 255,   1],\r\n#         [255, 255,   1],\r\n#         [255, 255,   1],\r\n#         [255, 255,   1],\r\n#         [255, 255,   1],\r\n#         [255, 255,   1],\r\n#         [255, 255,   1],\r\n#         [255, 255,   1]],\r\n#          ...,\r\n#allva=cyne.get_unique_dims_values()\r\ncyne.group_equal_values()\r\n#         [255, 255,   1]],\r\n#        [[255, 255,   1],\r\n#         [255, 255,   1],\r\n#         [255, 255,   1],\r\n\r\n#         [  0, 255, 255],\r\n#         [  0, 255, 255],\r\n#         ...\r\n\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255],\r\n#         [255, 255, 255]],\r\n\r\ngroupedvalues=cyne.group_equal_values()\r\nbyqty=cyne.sort_by_quantity(ascending=False)\r\ncyne.sort_by_hash(ascending=False)\r\n# Out[3]:\r\n# array([[                 270,                    9,                    0,                   10,  2497830064280488930],\r\n#        [                 240,                    8,                    0,                    9,  2497830064280488930],\r\n#        [                 210,                    7,                    0,                    8,  2497830064280488930],\r\n#        [                 180,                    6,                    0,                    7,  2497830064280488930],\r\n# ...\r\n#        [                 750,                   25,                    0,                    6, -5024405870974420794],\r\n#        [                 720,                   24,                    0,                    5, -5024405870974420794],\r\n#        [                 690,                   23,                    0,                    4, -5024405870974420794],\r\n#        [                 660,                   22,                    0,                    3, -5024405870974420794],\r\n#        [                 630,                   21,                    0,                    2, -5024405870974420794],\r\n#        [                 600,                   20,                    1,                    1, -5024405870974420794]], dtype=int64)\r\n\r\nclass HashSort(builtins.object)\r\n |  HashSort(a, unordered=True)\r\n |  \r\n |  The HashSort class is designed to perform sorting and grouping operations on multi-dimensional NumPy arrays\r\n |  using a hash-based algorithm. It utilizes the xxhash https://xxhash.com/ function (Cython! Not Python!) for efficient hash computation.\r\n |  \r\n |  Parameters:\r\n |  - a (numpy.ndarray): The input multi-dimensional NumPy array.\r\n |  - unordered (bool): If True, will create the index array with multi processing\r\n |  \r\n |  Methods:\r\n |  - generate_hash_array(last_dim=None): Generates a hash array based on the provided array and optional last_dim.\r\n |  - sort_by_absolut_index(ascending=True): Sorts the hash array by absolute index in ascending or descending order.\r\n |  - get_unique_dims_data(start_dim=0, end_dim=-1): Returns unique dimensions data based on hash array.\r\n |  - get_all_values(start_dim=0, end_dim=-1): Returns all values based on hash array and specified dimensions.\r\n |  - group_equal_values(start_dim=0, end_dim=-1): Groups equal values based on hash array and specified dimensions.\r\n |  - sort_by_hash(ascending=False): Sorts the hash array by hash values in ascending or descending order.\r\n |  - sort_by_quantity(ascending=False): Sorts the hash array by quantity values in ascending or descending order.\r\n |  \r\n |  Methods defined here:\r\n |  \r\n |  __init__(self, a, unordered=True)\r\n |      Initializes a new instance of the HashSort class.\r\n |      \r\n |      Parameters:\r\n |      - a (numpy.ndarray): The input multi-dimensional NumPy array.\r\n |      - unordered (bool): If True, will create the index array with multi processing\r\n |  \r\n |  generate_hash_array(self, last_dim=None)\r\n |      Generates a hash array based on the provided array and optional last_dim.\r\n |      \r\n |      Parameters:\r\n |      - last_dim (int, optional): The last dimension to consider. If None, uses the last dimension of the array.\r\n |      \r\n |      Returns:\r\n |      - HashSort: The current HashSort instance.\r\n |  \r\n |  get_all_values(self, start_dim=0, end_dim=-1)\r\n |      Returns all values based on hash array and specified dimensions.\r\n |      \r\n |      Parameters:\r\n |      - start_dim (int, optional): The starting dimension index to consider.\r\n |      - end_dim (int, optional): The ending dimension index to consider.\r\n |      \r\n |      Returns:\r\n |      - numpy.ndarray: All values based on the specified dimensions.\r\n |  \r\n |  get_shape_array(self, last_dim)\r\n |      Returns the shape array based on the provided last dimension.\r\n |      \r\n |      Parameters:\r\n |      - last_dim (int): The last dimension to consider.\r\n |      \r\n |      Returns:\r\n |      - Tuple: A tuple containing the shape array and the product of array shape elements from last_dim onwards.\r\n |  \r\n |  get_unique_dims_data(self, start_dim=0, end_dim=-1)\r\n |      Returns unique dimensions data based on hash array.\r\n |      \r\n |      Parameters:\r\n |      - start_dim (int, optional): The starting dimension index to consider.\r\n |      - end_dim (int, optional): The ending dimension index to consider.\r\n |      \r\n |      Returns:\r\n |      - List[numpy.ndarray]: A list containing unique dimensions data.\r\n |  \r\n |  group_equal_values(self, start_dim=0, end_dim=-1)\r\n |      Groups equal values based on hash array and specified dimensions.\r\n |      \r\n |      Parameters:\r\n |      - start_dim (int, optional): The starting dimension index to consider.\r\n |      - end_dim (int, optional): The ending dimension index to consider.\r\n |      \r\n |      Returns:\r\n |      - numpy.ndarray: Grouped values based on the specified dimensions.\r\n |  \r\n |  sort_by_absolut_index(self, ascending=True)\r\n |      Sorts the hash array by absolute index (np.flatten()/np.ravel() in ascending or descending order.\r\n |      \r\n |      Parameters:\r\n |      - ascending (bool, optional): If True, sorts in ascending order; otherwise, sorts in descending order.\r\n |      \r\n |      Returns:\r\n |      - numpy.ndarray: The sorted hash array.\r\n |  \r\n |  sort_by_hash(self, ascending=False)\r\n |      Sorts the hash array by hash values in ascending or descending order.\r\n |      \r\n |      Parameters:\r\n |      - ascending (bool, optional): If True, sorts in ascending order; otherwise, sorts in descending order.\r\n |      \r\n |      Returns:\r\n |      - numpy.ndarray: The sorted hash array.\r\n |  \r\n |  sort_by_quantity(self, ascending=False)\r\n |      Sorts the hash array by quantity values in ascending or descending order.\r\n |      \r\n |      Parameters:\r\n |      - ascending (bool, optional): If True, sorts in ascending order; otherwise, sorts in descending order.\r\n |      \r\n |      Returns:\r\n |      - numpy.ndarray: The sorted hash array.\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Fcythonnestednumpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhansalemaos%2Fcythonnestednumpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Fcythonnestednumpy/lists"}