{"id":17277634,"url":"https://github.com/ashkarin/ndpatch","last_synced_at":"2025-07-12T19:39:01.538Z","repository":{"id":57445306,"uuid":"150164495","full_name":"ashkarin/ndpatch","owner":"ashkarin","description":"Package to extract arbitrary regions from an N-dimensional numpy array assuming it mirrored infinitely.","archived":false,"fork":false,"pushed_at":"2019-05-08T17:32:04.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-30T09:43:20.385Z","etag":null,"topics":["array","data-structures","deep-neural-networks","image-processing","numpy","patches","region-of-interest"],"latest_commit_sha":null,"homepage":"","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/ashkarin.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-24T20:29:10.000Z","updated_at":"2021-07-06T05:44:10.000Z","dependencies_parsed_at":"2022-09-26T17:30:43.348Z","dependency_job_id":null,"html_url":"https://github.com/ashkarin/ndpatch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ashkarin/ndpatch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashkarin%2Fndpatch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashkarin%2Fndpatch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashkarin%2Fndpatch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashkarin%2Fndpatch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashkarin","download_url":"https://codeload.github.com/ashkarin/ndpatch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashkarin%2Fndpatch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265044470,"owners_count":23702941,"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":["array","data-structures","deep-neural-networks","image-processing","numpy","patches","region-of-interest"],"created_at":"2024-10-15T09:09:33.994Z","updated_at":"2025-07-12T19:39:01.479Z","avatar_url":"https://github.com/ashkarin.png","language":"Python","readme":".. image:: static/ndpatch.svg\n    :height: 120\n    :align: center\n    \n-----------\n\n.. image:: https://travis-ci.org/ashkarin/ndpatch.svg?branch=master \n    :target: https://travis-ci.org/ashkarin/ndpatch\n\n\n**NDPatch** is the package for extracting arbitrary regions from an N-dimensional numpy array assuming it mirrored infinitely.\n\nInstallation\n------------\n\nThe easiest way to install the latest version is by using pip::\n\n    $ pip install ndpatch\n\nYou may also use Git to clone the repository and install it manually::\n\n    $ git clone https://github.com/ashkarin/ndpatch.git\n    $ cd ndpatch\n    $ python setup.py install\n\nUsage\n-----\nTo take a patch from the array:\n\n.. code-block:: python\n\n  import numpy as np\n  import ndpatch\n  array = np.arange(25).reshape((5,5))\n  index = (1, 2)\n  shape = (3, 3)\n  patch = ndpatch.get_ndpatch(array, shape, index)\n  # patch =\n  # [[ 7,  8,  9],\n  #  [12, 13, 14],\n  #  [17, 18, 19]]\n\nTo take get a random patch index:\n\n.. code-block:: python\n\n  import numpy as np\n  import ndpatch\n  array_shape = (5, 5)\n  index = ndpatch.get_random_patch_index(array_shape)\n\nTo extract random patches from the array:\n\n.. code-block:: python\n\n  import numpy as np\n  import ndpatch\n  npatches = 10\n  patch_shape = (3, 3)\n  array = np.arange(100).reshape((10,10))\n  patches = [ndpatch.get_random_ndpatch(array, patch_shape) for _ in range(npatches)]\n\nTo split the 3D array on set of overlapping 3D patches and rebuild it back:\n\n.. code-block:: python\n\n  import numpy as np\n  import ndpatch\n  array = np.arange(0, 125).reshape((5,5,5))\n  patch_shape = (4, 3, 3)\n  overlap = 2\n  indices = ndpatch.get_patches_indices(array.shape, patch_shape, overlap)\n  patches = [ndpatch.get_ndpatch(array, patch_shape, index) for index in indices]\n  reconstructed = ndpatch.reconstruct_from_patches(patches, indices, array.shape, default_value=0)\n  # Validate\n  equal = (reconstructed == array)\n  assert (np.all(equal))\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashkarin%2Fndpatch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashkarin%2Fndpatch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashkarin%2Fndpatch/lists"}