Skip to content

Tag: numpy

Using PyTorch tensors with scikit-learn

Can I use PyTorch tensors instead of NumPy arrays while working with scikit-learn? I tried some methods from scikit-learn like train_test_split and StandardScalar, and it seems to work just fine, but is there anything I should know when I’m using PyTorch tensors instead of NumPy arrays? According to thi…

Find center of blocks of ones in an 2d array

Lets assume I have the following array and want to get the center of each block of ones, so that I can get the following array: I already thought about using means or convolutions, but I couldn’t think of a really simple solution. One in efficient solution that I found is: Answer This is a little less i…

Zipping two np.array into array

Im trying to combine following two np.arrays into a single array: The combination array must look like this [[i, pred, boxes],…]: I tried doing it this way, but it unfortunately didn’t work: Is there a way to do this? I tried other means but those tries were even worse. Answer Try hstack:

Apply threshold for numpy.ndarray

I have a model predictions type of numpy.ndarray The predictions looks like where the first value of inner array corresponds to 0 class and the second value corresponds to 1 class. For this y_pred i need to apply FNR threshold 0.21552509277542697, which i also calculated. That is the efficient numpy way to do…