从nDarrays中提取任意n维区域。

ndpatch的Python项目详细描述


static/ndpatch.svg
https://travis-ci.org/ashkarin/ndpatch.svg?branch=master

ndpatch是一个用于从n维numpy数组中提取任意区域的包,假设它无限镜像。

安装

安装最新版本的最简单方法是使用pip:

$ pip install ndpatch

您还可以使用git克隆存储库并手动安装:

$ git clone https://github.com/ashkarin/ndpatch.git
$ cd ndpatch
$ python setup.py install

用法

从阵列中获取修补程序:

importnumpyasnpimportndpatcharray=np.arange(25).reshape((5,5))index=(1,2)shape=(3,3)patch=ndpatch.get_ndpatch(array,shape,index)# patch =# [[ 7,  8,  9],#  [12, 13, 14],#  [17, 18, 19]]

获取随机补丁索引:

importnumpyasnpimportndpatcharray_shape=(5,5)index=ndpatch.get_random_patch_index(array_shape)

从阵列中提取随机补丁:

importnumpyasnpimportndpatchnpatches=10patch_shape=(3,3)array=np.arange(100).reshape((10,10))patches=[ndpatch.get_random_ndpatch(array,patch_shape)for_inrange(npatches)]

要在一组重叠的三维面片上拆分三维阵列并将其重新生成,请执行以下操作:

importnumpyasnpimportndpatcharray=np.arange(0,125).reshape((5,5,5))patch_shape=(4,3,3)overlap=2indices=ndpatch.get_patches_indices(array.shape,patch_shape,overlap)patches=[ndpatch.get_ndpatch(array,patch_shape,index)forindexinindices]reconstructed=ndpatch.reconstruct_from_patches(patches,indices,array.shape,default_value=0)# Validateequal=(reconstructed==array)assert(np.all(equal))

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Spring 4升级后未加载java应用程序上下文   java Android 2.3.3 internet可以在我的Galaxy S上运行,但不能在我的Galaxy选项卡上运行?(许可?)   java通过不改变其原始位置对大小写字母进行排序   java Spring Boot一直在破坏我的电脑。。。sts的最佳配置是什么。Windows 10上的ini文件?   css Java Spring+引导问题   java Jackson将GeoJsonPoint序列化为纬度/经度   xml Java Transformer:如何将其结果生成OutputStream?   java如何更改字体、文本大小和设置文本位置?   在JavaSpringHibernate3.6.3中,如何告诉一个方法等待,直到获得锁,以及如何重试失败的事务?   java安卓服务代替线程   Java Swing使用鼠标移动JFrame