如何在Python中对数组进行重新采样
我是 python 新手,我有一个关于数组/矩阵的问题。 下面是我得到的矩阵。
A=
[[85 77 83 ..., 59 58 59]
[80 83 80 ..., 57 60 58]
[75 76 81 ..., 59 58 60]]
我想重新采样(我不知道如果这是正确的词)矩阵,所以它变成
B =
[[ 85 85 85 85 77 77 77 77 83 83 83 83 ...... 59 59 59 59 58 58 58 58 59 59 59 59]
[ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59 59 59]
[ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59 59 59]
[ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59 59 59]
[ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58 58 58]
[ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58 58 58]
[ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58 58 58]
[ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58 58 58]
[ 75 75 75 75 76 76 76 76 81 81 81 81 ...... 59 59 59 59 58 58 58 58 60 60 60 60]
[ 75 75 75 75 76 76 76 76 81 81 81 81 ...... 59 59 59 59 58 58 58 58 60 60 60 60]
[ 75 75 75 75 76 76 76 76 81 81 81 81 ....... 59 59 59 59 58 58 58 58 60 60 60 60]]
我在网上搜索并查看了很多帖子,但我仍然不知道如何做到这一点。 所以请教我如何做到这一点,我非常感激。
I am new in python and I have a question about array/matrix.
Below is the matrix I got.
A =
[[85 77 83 ..., 59 58 59]
[80 83 80 ..., 57 60 58]
[75 76 81 ..., 59 58 60]]
I want to re-sample(I don't know if this is the right word) the matrix so it becomes
B =
[[ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59 59 59]
[ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59 59 59]
[ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59 59 59]
[ 85 85 85 85 77 77 77 77 83 83 83 83 ....... 59 59 59 59 58 58 58 58 59 59 59 59]
[ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58 58 58]
[ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58 58 58]
[ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58 58 58]
[ 80 80 80 80 83 83 83 83 80 80 80 80 ....... 57 57 57 57 60 60 60 60 58 58 58 58]
[ 75 75 75 75 76 76 76 76 81 81 81 81 ....... 59 59 59 59 58 58 58 58 60 60 60 60]
[ 75 75 75 75 76 76 76 76 81 81 81 81 ....... 59 59 59 59 58 58 58 58 60 60 60 60]
[ 75 75 75 75 76 76 76 76 81 81 81 81 ....... 59 59 59 59 58 58 58 58 60 60 60 60]]
I searched online and looked at many posts, but still I have no clue how to do this.
So please teach me how to do this, and I am greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
绝对使用 Scipy 插值如何调整大小/重新采样的信息3x3 矩阵到 5x5? 来自评论。
但我想我会乱搞,这就是我得到的:
可能是有史以来最糟糕的方法:
Definitely use the info from Scipy interpolation how to resize/resample 3x3 matrix to 5x5? from the comments.
But I thought I'd mess around and here's what I got:
Possibly the worst looking method of all time:
以下实现以递归方式对包含数字(任何不可迭代对象)的矩阵或列表(任何可迭代容器类型)进行重新采样(重复)。与其他替代方案相比,它速度更快且更容易理解。它可以处理任意嵌套的列表。每个子列表都被正确地深度复制。
用法:
The following implementation recursively resamples (duplicates) a matrix or a list (any iterable container type) containing numbers (any non-iterable objects). It is fast and much simpler to comprehend than other alternatives. It can handle arbitrarily-nested lists. Every sublist is properly deep-copied.
Usage:
我并不完全理解您的算法或您想要做什么,但是:
请注意,它适用于任何数组,因为它仅使用基本语言原语
I didn't exactly understand your algorithm or what you want to do, but:
Note that it works with arrays of anything as it uses only the base language primitives
即使现在回答有点晚了,我还是想对此发表一些评论!
Even it is a bit late for the answer I preferred to give some comments on it!