python

Getting Rid of the non-significant terms in symbolic equations in sympy

Getting Rid of the non-significant terms in symbolic equations in sympy Question: I am trying to obtain significant terms from a symbolic expression obtained using sympy. The expressions represent symbolic dynamics of a a manipulator arm. The expression has the numerical coefficient always in the zeroth argument. However, the coefficients can be both positive and …

Total answers: 1

change KeyboardInterrupt to 'enter'

change KeyboardInterrupt to 'enter' Question: I have the following code: import time def run_indefinitely(): while True: # code to run indefinitely goes here print("Running indefinitely…") time.sleep(1) try: # Run the code indefinitely until Enter key is pressed run_indefinitely() except KeyboardInterrupt: print("Loop interrupted by user") Is there a way to break out of the while loop …

Total answers: 2

Unexpected behaviour of log1p numpy

Unexpected behaviour of log1p numpy Question: I am using the function numpy.log1p to calculate the value of log(1 + x) for very small complex numbers, and I am getting unexpected results. I would expect that outputs should be practically equal to the function input. While this does not seem to be the case in the …

Total answers: 2

How to split an array using its minimum entry

How to split an array using its minimum entry Question: I am trying to split a dataset into two separate ones by finding its minimum point in the first column. I have used idxmin to firstly identify the location of the minimum entry and secondly iloc to slice the array from 0 to the minimum …

Total answers: 1

np.unique after np.round unrounds the data

np.unique after np.round unrounds the data Question: This code snippet describes a problem I have been having. For some reason rounded_data seems to be rounded, but once passed in np.unique and np.column_stack the result_array seems to be unrounded, meanwhile the rounded_data is still rounded. rounded_data = data_with_target_label.round(decimals=2) unique_values, counts = np.unique(rounded_data, return_counts=True) result_array = np.column_stack((unique_values, …

Total answers: 1

Polars: Replace parts of dataframe with other parts of dataframe

Polars: Replace parts of dataframe with other parts of dataframe Question: I’m looking for an efficient way to copy / replace parts of a dataframe with other parts of the same dataframe in Polars. For instance, in the following minimal example dataframe pl.DataFrame({ "year": [2020,2021,2020,2021], "district_id": [1,2,1,2], "distribution_id": [1, 1, 2, 2], "var_1": [1,2,0.1,0.3], "var_N": …

Total answers: 4

Multiple gaussian fit issue

Multiple gaussian fit issue Question: I have this code that aims to fit the data in here https://drive.google.com/file/d/1uBrHxuftALiQTcTeBl-s6AHGiC8DGBWV/view?usp=sharing. Where the function read_file is used to stract the information in a proper way. I do not what i am doing wrong that the gaussian fit is not right as you can see in the image (Gaussian …

Total answers: 1

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