Categories
Mastering Development

How to solve floating point error when comparing two numbers

import math from fractions import Fraction Lis = [ 1, 2 , 3 , 6 , 1/2 , 1/3 , 1/4 , 1/6 , 1/12 , 2/3, 3/2, 3/4, -1,-2,-3,-6, -1/2 , -1/3 , -1/4 , -1/6 , -1/12 , -2/3, -3/2, -3/4 ] for x in lis: if abs((12(x^3) – 32 (x^2) + 25 […]

Categories
Mastering Development

How to calculate movement of pendulum?

I am trying to make a simple simulation of pendulum using Runge–Kutta fourth-order method. I am using p5.js. Usually it calculates the angles properly but sometimes it just starts spinning randomly etc. I have no idea how to resolve this issue it seems to be a problem with my implementation of said algorithm I think? […]

Categories
Mastering Development

C++/Cpp Function Alters Value of Passed Parameter

I have a simple swapping function to take an integer array, and return a new array with swapped values. ”’ int* Node::dataSwap(int *data, int n_index, int swap_index){ printDatt(data); int *path = data; int swapped = data[n_index]; int to_swap = data[swap_index]; path[n_index] = to_swap; path[swap_index] = swapped; printDatt(data); return path; } ”’ However, the reference to […]

Categories
Mastering Development

Python – Combination

I am new to Python, facing a big challenge on work with finding which 2 Suppliers can produce all products. In this Case, Supplier A & Supplier B are sufficient to fulfill(Either A or B can produce the product), which means only contracting with A & B can complete the production. I totally have no […]

Categories
User Help

Group by Year and ID and then sum

I have table with 3 columns – ID, Year and Value. Example of the table: Some rows from the picture: id, year ,value 1, 2017 ,19 1, 2017 ,21 1, 2017 ,22 1, 2018 ,1 1, 2018 ,30 1, 2018 ,15 1, 2018 ,17 1, 2018 ,2 1, 2018 ,18 1, 2019 ,23 1, 2019 […]

Categories
Mastering Development

Sorting dataframe by absolute value of a row

I have the following dataframe: import pandas as pd data = {0: [-1, -14], 1: [-3, 2], 2: [7, 10], 4: [-10, 15]} df = pd.DataFrame(data) I know how to sort an specific row: df.sort_values(by=0, ascending=False, axis=1) How is it possible to sort the dataframe by the absolute value of the first row? In this […]

Categories
Mastering Development

python seaborn: customize line plot and scatterplot together (also legend)

df = pd.DataFrame({ ‘id’: {0: -3, 1: 2, 2: -3, 3: 1}, ‘val’: {0: 0.4, 1: 0.03, 2: 0.88, 3: 1.3}, ‘indicator’: {0: ‘A’, 1: ‘A’, 2: ‘B’, 3: ‘B’}, ‘count’: {0: 40000, 1: 5779, 2: 3000, 3: 31090} }) df and I hope to get a plot like the following: I know with code […]

Categories
Mastering Development

Make a new variable, var3, by taking the count of all values of var1 and dividing by unique values of var1, over unique values of var2

I’m trying to plot the average number of clicks on a given day over a one week period. The data i’m working with can be found here if you want to take a look. But briefly, it is structured as so: <class ‘pandas.core.frame.DataFrame’> RangeIndex: 400165 entries, 0 to 400164 Data columns (total 9 columns): uuid […]

Categories
Mastering Development

Insert values between other values in numpy array

Let’s say I start with this array: start_array = [[1.48, 1.79, 2.10, 2.80] [63, 60, 57, 60]] I want to take the values in this second array: second_array = np.array([2.3,3.42, 4.47]) and insert them in in between the values in the first row, with a 1 in another row to code that something occurred there. […]

Categories
Ask Games RPG Games

How to calculate probability of values under Weibull distribution?

I have a Genomic data that shows the interaction between genomic regions that I would like to understand which interactions are significant statistically. Dataset look likes: chr start1 end1 start2 end2 normalized count 1 500 1000 2000 3000 1.5 1 500 1000 4500 5000 3.2 1 2500 3500 1000 2000 4 So, I selected a […]