英文:
Value Error (At least one stride in the given numpy array is negative) Remains After Copying Array
问题
我使用以下命令对从另一个Python文件导入的NumPy数组进行了排序:
import numpy as np
from test import c_A
cA = c_A.reshape(10000, 1)
c = np.sort(cA, axis=0)[::-1]
然后我遇到了以下错误:
ValueError: 给定的NumPy数组中至少有一个步幅为负数,目前不支持具有负步幅的张量。(您可能可以通过使用array.copy()来解决这个问题,制作数组的副本。)
因此,我复制了数组,并相应调整了我的代码:
cA = c_A.reshape(10000, 1)
cA2 = torch.from_numpy(cA.copy())
c = np.sort(cA2, axis=0)[::-1]
相同的错误仍然存在,并且显示“torch”未定义。
我正在使用Nvidia Modulus,这是一个使用PyTorch的DL框架。
在线上看到的复制数组方法并没有起作用。
我应该怎么做?
数组应该保持为大小为[N,1]的NumPy数组字典。
英文:
I sorted a numpy array that I imported from another python file using the following commands:
import numpy as np
from test import c_A
cA=c_A.reshape(10000,1)
c=np.sort(cA,axis=0)[::-1]
I then get the following error:
> ValueError: At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supported. (You can probably work around this by making a copy of your array with array.copy().)
So, I copied the array, and adjusted my code accordingly:
cA=c_A.reshape(10000,1)
cA2 = torch.from_numpy(cA.copy())
c=np.sort(cA2,axis=0)[::-1]
The same error remains, and it says "torch" is not defined.
I am using Nvidia Modulus, a DL framework that uses PyTorch.
The copied array method that I have been seeing online, which did not work.
How to I go about this?
The array should also remain as a dictionary of numpy array of size [N,1].
答案1
得分: 1
你的错误提示是torch未定义,它未在你的代码中导入,让我们添加它,同时确保在你的系统上已安装它 pip install torch
import torch
import numpy as np
from test import c_A
cA = c_A.reshape(10000, 1)
cA2 = torch.from_numpy(cA.copy())
c, _ = torch.sort(cA2, dim=0, descending=True)
英文:
Your error say that torch is not defined, it has not been imported in your code, lets just add it, also be sure to have have it installed on your system pip install torch
import torch
import numpy as np
from test import c_A
cA = c_A.reshape(10000,1)
cA2 = torch.from_numpy(cA.copy())
c, _ = torch.sort(cA2, dim=0, descending=True)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论