Skip to content
Advertisement

Tag: numpy

Numba: indexing a vector is giving an error

I started using python and numba recently. My problem is: I have a matrix (n rows and m columns).In a for loop I have to change the values ​​of specific columns. Without numba, the code is running fine. But when I use njit(), it just crashes. Note: In my real project, each row don’t have the same values. This is

reshape the array with specific form

I have an specific array which each rows has to array. I want to reshape it. But, I don’t know how to reshape it to a 2d array. Here is my array: Here is the desired output: Any help appreciated. Thanks I’ve tried to use the reshape. But, it does not solve. Answer It’s ragged, it’s not concatenated. Is it

Resolving conflicts in Pandas dataframe

I am performing record linkage on a dataframe such as: When my model overpredicts and links the same ID_1 to more than one ID_2 (indicated by a 1 in Predicted Link) I want to resolve the conflicts based on the Probability-value. If one predicted link has a higher probability than the other I want to keep a 1 for that,

np.where for 2d array, manipulate whole rows

I want to rebuild the following logic with numpy broadcasting function such as np.where: From a 2d array check per row if the first element satisfies a condition. If the condition is true then return the first three elements as a row, else the last three elements. A short MWE in form of a for-loop which I want to circumvent:

Images Have Grey Values of True and False

I’m planning to process some images using PyCharm. However, I find a bug and start to find the reason. Finally, I find that the images have grey values of True and False, but they should be 1 and 0, is there any way to change it? The image is generated in PyCharm using: The Python version is 3.8.12. Answer You

Import large .tiff file as sparse matrix

I have a large .tiff file (4.4gB, 79530 x 54980 values) with 1 band. Since only 16% of the values are valid, I was thinking it’s better to import the file as sparse matrix, to save RAM. When I first open it as np.array and then transform it into a sparse matrix using csr_matrix(), my kernel already crashes. See code

Deduplicate numpy array by another array

I have two numpy arrays: a is the index of items, and b is the score of corresponding items. Now I want to sort these items descendingly by the scores in b while only keeping the largest score of a single item. The results should be the non-duplicated item index a_new and the score of these items b_new. In the

Advertisement