相关疑难解决方法(0)

连续和非连续数组之间有什么区别?

在关于reshape()函数的numpy手册中,它说

>>> a = np.zeros((10, 2))
# A transpose make the array non-contiguous
>>> b = a.T
# Taking a view makes it possible to modify the shape without modifying the
# initial object.
>>> c = b.view()
>>> c.shape = (20)
AttributeError: incompatible shape for a non-contiguous array
Run Code Online (Sandbox Code Playgroud)

我的问题是:

  1. 什么是连续和不连续的数组?它是否类似于C中的连续内存块,比如什么是连续的内存块?
  2. 这两者之间有任何性能差异吗?我们什么时候应该使用其中一种?
  3. transpose为什么使数组不连续?
  4. 为什么c.shape = (20)抛出错误incompatible shape for a non-contiguous array

感谢您的回答!

python memory arrays numpy

73
推荐指数
2
解决办法
4万
查看次数

什么是连续的内存块?

就像在标题中一样,什么是连续的内存块?

c memory heap heap-fragmentation

38
推荐指数
3
解决办法
3万
查看次数

python opencv TypeError:输出数组的布局与cv :: Mat不兼容

我在这里使用选择性搜索:http://koen.me/research/selectivesearch/ 这给出了一个对象可能存在的感兴趣区域.我想进行一些处理并仅保留一些区域,然后删除重复的边界框以获得最终整齐的边界框集合.为了丢弃不需要/重复的边界框区域,我使用grouprectanglesopencv 的功能进行修剪.

一旦我从上面链接中的"选择性搜索算法"中获取Matlab中的有趣区域,我将结果保存在一个.mat文件中,然后在python程序中检索它们,如下所示:

 import scipy.io as sio
 inboxes = sio.loadmat('C:\\PATH_TO_MATFILE.mat')
 candidates = np.array(inboxes['boxes'])
 # candidates is 4 x N array with each row describing a bounding box like this: 
 # [rowBegin colBegin rowEnd colEnd]
 # Now I will process the candidates and retain only those regions that are interesting
 found = [] # This is the list in which I will retain what's interesting
 for win in candidates: 
     # doing some processing …
Run Code Online (Sandbox Code Playgroud)

python arrays matlab opencv numpy

10
推荐指数
5
解决办法
3万
查看次数

标签 统计

arrays ×2

memory ×2

numpy ×2

python ×2

c ×1

heap ×1

heap-fragmentation ×1

matlab ×1

opencv ×1