python

Optimization of pytorch function to eliminate for loop

Optimization of pytorch function to eliminate for loop Question: lately I have been developing a function capable of dealing with tensors with dimension: torch.Size([51, 265, 23, 23]) where the first dim is time, the second is pattern and the last 2 are pattern size. Each individual pattern can have a maximum of 3 states: [-1,0,1], …

Total answers: 1

Loading pre-trained weights properly in Pytorch

Loading pre-trained weights properly in Pytorch Question: I would like to perform transfer learning by loading a pretrained vision transformer model, modify its last layer and training it with my own data. Hence, I am loading my dataset perform the typical transformation similar to the ImageNet, then, load the model, disable the grad from all …

Total answers: 1

bokeh vbar_stack: positive values on positive side, negative values on negative side

bokeh vbar_stack: positive values on positive side, negative values on negative side Question: Example program import bokeh.colors import pandas as pd from bokeh.plotting import figure, show import bokeh.models import bokeh.palettes import bokeh.transform data = { ‘date’: [‘2024-04-15’, ‘2024-04-16’, ‘2024-04-17’ ], ‘Bill’: [1, 1, -1], ‘Note’: [1, -1, -1], ‘Bond’: [1, 0, -1] } df = …

Total answers: 1

LinkedList merge_sorted infinite loop

LinkedList merge_sorted infinite loop Question: I keep getting into an infinite loop when using my function merge_sorted for my linked lists. Please help. Thanks 🙂 I went through my merge_sort function and it seems okay. It updates the curr1 and curr2 inside the loop but I am not sure why I get into the infinite …

Total answers: 2

Python library: optionally support numpy types without depending on numpy

Python library: optionally support numpy types without depending on numpy Question: Context We develop a Python library that contains a function expecting a numlike parameter. We specify this in our signature and make use of python type hints: def cool(value: float | int | List[float | int]) Problem & Goal During runtime, we noticed it’s …

Total answers: 1

peak integration using trapz but not starting from baseline and visualization

peak integration using trapz but not starting from baseline and visualization Question: I am trying to integrate signal peaks using numpy.trapz or scipy.trapz. I do manually select the range of a peak min and max. the problem I am facing is that I think these functions integerates the AUC till the baseline. Sometimes my signal …

Total answers: 1

Image Pyramid. Having trouble creating the desired composite image

Image Pyramid. Having trouble creating the desired composite image Question: What I am trying to do: Combine these two images: Using this mask: to create this output: The assignment: Write a program to create a composite image of the two images with the mask, based on image pyramids. Now, This is what I have tried …

Total answers: 1

Find all files matching given path format with datetime

Find all files matching given path format with datetime Question: I’m looking to identify all files whose path matches a given format (for example %Y/%j/data_%d.txt) and retrieve the associated date. A simple solution is to use strptime, but this doesn’t work if a ‘format code’ appears twice in the format (e.g. %Y/%j/data_%Y%m%d.txt). This is a …

Total answers: 1

Subsetting netcdf files with multiple variables by time range

Subsetting netcdf files with multiple variables by time range Question: I have hundreds of netcdf files, each with 18 variables. The data in each file dates from 1850 to 2100 and roughly 20GB each. CDO and NCO could not read the data due to the rotation because the extent (-1.40625, 358.5938, 89.25846, 89.25846) is unusual …

Total answers: 1

os.path.isfile() returns False for a file that can be found with the explorer

os.path.isfile() returns False for a file that can be found with the explorer Question: Hi I am trying to read in and display a picture with cv2 for further analysis with the following code: Edit: I added the path with my username being clear to prove it doesn’t contain wacky characters. I also tried with …

Total answers: 2