在关于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)
我的问题是:
c.shape = (20)抛出错误incompatible shape for a non-contiguous array?感谢您的回答!
在numpy中,我们ndarray.reshape()用于重塑数组.
我注意到在pytorch中,人们使用torch.view(...)同样的目的,但同时也torch.reshape(...)存在.
所以我想知道他们和我应该使用其中任何一个之间的差异是什么?