相关疑难解决方法(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万
查看次数

标签 统计

arrays ×1

memory ×1

numpy ×1

python ×1