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

如何在numpy的数组中索引轴?

Numpy的教程中,轴可以用整数编制索引,就像0用于列,1用于行,但我不明白为什么它们以这种方式编入索引?在处理多维数组时,如何计算每个轴的索引?

python numpy

63
推荐指数
4
解决办法
5万
查看次数

numpy多维数组中的轴

我还没有理解numpy中多维数组中的轴之间的差异。你能解释一下吗?我特别想知道numpy三维数组中的axis0,axis1和axis2在哪里。又为什么呢?谢谢。

python numpy

4
推荐指数
1
解决办法
6652
查看次数

numpy.transpose的时间复杂度

np.transpose的时间复杂度是多少?

在我看来,它在内部循环了两个for循环,这意味着它应该具有O(n2)复杂度,但有人可以对此进行确认吗?另外,有什么办法可以减少矩阵转置的时间复杂度

python numpy python-3.x

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

标签 统计

numpy ×4

python ×4

arrays ×1

memory ×1

python-3.x ×1