{"id":23448265,"url":"https://github.com/hansalemaos/cythonflatiter","last_synced_at":"2026-05-15T20:31:14.119Z","repository":{"id":211500375,"uuid":"729344235","full_name":"hansalemaos/cythonflatiter","owner":"hansalemaos","description":"Locates values in NumPy Arrays with Cython","archived":false,"fork":false,"pushed_at":"2023-12-09T00:30:27.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-07T21:18:17.070Z","etag":null,"topics":["cython","isin","iter","numpy"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/cythonflatiter","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-09T00:30:07.000Z","updated_at":"2023-12-19T11:04:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"cd4a7db6-9f5a-4abd-b0ca-0ce29a10c8c0","html_url":"https://github.com/hansalemaos/cythonflatiter","commit_stats":null,"previous_names":["hansalemaos/cythonflatiter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hansalemaos/cythonflatiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythonflatiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythonflatiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythonflatiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythonflatiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hansalemaos","download_url":"https://codeload.github.com/hansalemaos/cythonflatiter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Fcythonflatiter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33078898,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cython","isin","iter","numpy"],"created_at":"2024-12-23T22:14:23.800Z","updated_at":"2026-05-15T20:31:14.100Z","avatar_url":"https://github.com/hansalemaos.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Locates values in NumPy Arrays with Cython\r\n\r\n\r\n## pip install cythonflatiter\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\nFlatIterArray is a utility class for efficiently searching multi-dimensional array data.\r\n\r\n```python\r\n |  __init__(self, a, dtype=\u003cclass 'numpy.int64'\u003e, unordered=True)\r\n |      Initializes a FlatIterArray instance.\r\n |      \r\n |      Parameters:\r\n |      - a (numpy.ndarray): The input array.\r\n |      - dtype (numpy.dtype, optional): The data type of the index array that will be created. Defaults to np.int64. (It's better not to change that, because it corresponds to cython.Py_ssize_t)\r\n |      - unordered (bool, optional): Flag indicating whether to use unordered iterations. Defaults to True. (index array will be created using multiprocessing)\r\n |  \r\n |  get_flat_pointer_array_from_orig_data(self)\r\n |      Returns a flat pointer array from the original data.\r\n |      If you change data here, it changes also in the original array\r\n |      \r\n |      Returns:\r\n |      - numpy.ndarray: Flat pointer array.\r\n |  \r\n |  search_multiple_values_in_array(self, values)\r\n |      Searches for multiple values in the array and returns indices and values.\r\n |      \r\n |      Parameters:\r\n |      - values (list or numpy.ndarray): List of values to search for.\r\n |      \r\n |      Returns:\r\n |      - tuple: Array of indices and array of found values.\r\n |  \r\n |  search_single_value_in_array(self, value)\r\n |      Searches for a single value in the array and returns indices.\r\n |      \r\n |      Parameters:\r\n |      - value: The value to search for.\r\n |      \r\n |      Returns:\r\n |      - numpy.ndarray: Array of indices.\r\n |  \r\n |  sequence_is_in_dimension(self, seq, last_dim)\r\n |      Checks if a sequence is in a dimension\r\n |      \r\n |      Parameters:\r\n |      - seq (list or numpy.ndarray): List of values representing the sequence.\r\n |      - last_dim: The dimension to search in.\r\n |      \r\n |      Returns:\r\n |      - numpy.ndarray: Array of indices.\r\n |  \r\n |  update_iterarray(self, dtype=\u003cclass 'numpy.int64'\u003e, unordered=True)\r\n |      Updates the iterray attribute with new parameters.\r\n |      \r\n |      Parameters:\r\n |      - dtype (numpy.dtype, optional): The data type of the index array that will be created. Defaults to np.int64.\r\n |      - unordered (bool, optional): Flag indicating whether to use unordered iterations. Defaults to True. (index array will be created using multiprocessing)\r\n |  \r\n |  value_is_in_dimension(self, value, last_dim)\r\n |      Checks if a value is in a dimension\r\n |      \r\n |      Parameters:\r\n |      - value: The value to search for.\r\n |      - last_dim: The dimension to search in.\r\n |      \r\n |      Returns:\r\n |      - numpy.ndarray: Array of indices.\r\n \r\n import numpy as np\r\nimport cv2\r\nfrom cythonflatiter import FlatIterArray\r\n\r\ndata = cv2.imread(r\"C:\\Users\\hansc\\Desktop\\2023-08-29xx16_07_30-Window.png\")\r\nf = FlatIterArray(data, dtype=np.int64, unordered=True)\r\nresults255inarray = f.search_single_value_in_array(255)\r\n# results255inarray\r\n# Out[6]:\r\n# array([[195330,     34,      0,      0],\r\n#        [201075,     35,      0,      0],\r\n#        [206820,     36,      0,      0],\r\n#        ...,\r\n#        [488324,     84,   1914,      2],\r\n#        [494069,     85,   1914,      2],\r\n#        [499814,     86,   1914,      2]], dtype=int64)\r\n# print(data[84,1914,2])\r\n# print(data[34,0,0])\r\n# 255\r\n# 255\r\nindices, found_values = f.search_multiple_values_in_array(values=[255, 11, 0])\r\n# indices,found_values\r\n# Out[12]:\r\n# (array([[195330,     34,      0,      0],\r\n#         [201075,     35,      0,      0],\r\n#         [206820,     36,      0,      0],\r\n#         ...,\r\n#         [488324,     84,   1914,      2],\r\n#         [494069,     85,   1914,      2],\r\n#         [499814,     86,   1914,      2]], dtype=int64),\r\n#  array([255, 255, 255, ..., 255, 255, 255], dtype=uint8))\r\nconcat_values = np.hstack([indices, found_values.reshape((-1, 1))])\r\n# print(concat_values)\r\n# [[195330     34      0      0    255]\r\n#  [201075     35      0      0    255]\r\n#  [206820     36      0      0    255]\r\n#  ...\r\n#  [488324     84   1914      2    255]\r\n#  [494069     85   1914      2    255]\r\n#  [499814     86   1914      2    255]]\r\n# print(data[85,1914,2])\r\n# print(data[36,0,0])\r\nlastdimwith255 = f.value_is_in_dimension(255, 3)\r\n# lastdimwith255\r\n# Out[31]:\r\n# array([[195330,     34,      0],\r\n#        [201075,     35,      0],\r\n#        [206820,     36,      0],\r\n#        ...,\r\n#        [488322,     84,   1914],\r\n#        [494067,     85,   1914],\r\n#        [499812,     86,   1914]], dtype=int64)\r\n# print(data[86,1914])\r\n# print(data[34,0])\r\n# [255 255 255]\r\n# [255 255 255]\r\npenultimatedimwith255255 = f.sequence_is_in_dimension([255, 255, 255], 2)\r\n# penultimatedimwith255255\r\n# Out[38]:\r\n# array([[      0,       0],\r\n#        [   5745,       1],\r\n#        [  11490,       2],\r\n#        ...,\r\n#        [5538180,     964],\r\n#        [5543925,     965],\r\n#        [5549670,     966]], dtype=int64)\r\n# data[964]\r\n# Out[40]:\r\n# array([[255, 255, 255],\r\n#        [255, 255, 255],\r\n#        [255, 255, 255],\r\n#        ...,\r\n#        [ 43,  43,  43],\r\n#        [ 43,  43,  43],\r\n#        [ 43,  43,  43]], dtype=uint8)\r\n\r\nultimatedimwith255255255 = f.sequence_is_in_dimension([255, 255, 255], 3)\r\n# ultimatedimwith255255255\r\n# Out[42]:\r\n# array([[195330,     34,      0],\r\n#        [201075,     35,      0],\r\n#        [206820,     36,      0],\r\n#        ...,\r\n#        [488322,     84,   1914],\r\n#        [494067,     85,   1914],\r\n#        [499812,     86,   1914]], dtype=int64)\r\n\r\n# [750 433   0]\r\n# [751 433   0]\r\n# [752 433   0]\r\n# [753 433   0]\r\n# [754 433   0]\r\n# [755 433   0]\r\n# [756 433   0]\r\n# [757 433   0]\r\n# [758 433   0]\r\n\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Fcythonflatiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhansalemaos%2Fcythonflatiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Fcythonflatiter/lists"}