Python:将2D数组映射到更大的2D数组的一般规则

时间:2017-02-02 14:40:56

标签: python arrays numpy slice

假设您有一个2D numpy数组,您已经切片以提取其核心,就像您从较大的框架中删除内部框架一样

更大的框架:

In[0]: import numpy
In[1]: a=numpy.array([[0,1,2,3,4],[5,6,7,8,9],[10,11,12,13,14],[15,16,17,18,19]])
In[2]: a
Out[2]: 
array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19]]) 

内框:

In[3]: b=a[1:-1,1:-1]
Out[3]: 
array([[ 6,  7,  8],
       [11, 12, 13]])

我的问题:如果我想检索原始数组ba中每个值的位置,是否有比这更好的方法?

c=numpy.ravel(a) #This will flatten my values in a, so to have a sequential order
d=numpy.ravel(b) #Each element in b will tell me what its corresponding position in a was

1 个答案:

答案 0 :(得分:1)



`           mClient = new WebClient();`

`           mUrl = new Uri("http://...link.../login");`

`           mClient.DownloadDataAsync(mUrl);`