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].
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)