Cumulatively merge rows with the same index

In python pandas, I have a dataframe which looks something like this: > df count date 2021-04-03 23.0 2021-04-04 12.0 2021-04-04 10.0 2021-04-05 42.0 2021-04-06 …

comparing numpy arrays with np.allclose()

I am new to Python. I cannot understand the behavior of the following code (I am trying to create a unit test for something): import numpy as np input = np.array([0, 2]) result = 1 / (1 + …

Replace duplicate value with NaN using groupby

Dataset(MWE) location date people_vaccinated people_fully_vaccinated people_vaccinated_per_hundred AL 12-01-2021 70861 7270 1.45 AL 13-…

mask and apply numpy where function to a vector in c++

I’m in C++ and I want to combine the masking of a vector and the search for the indexes where a condition is verified, similarly to the numpy where function. I show you an example. I have these …

PyTorch – AssertionError: Size mismatch between tensors

I am trying to adapt a Pytorch script that was created for linear regression. It was originally written to take in a set of random values(created with np.random) as features and targets. I have now …

how to split a list of numpy arrays and concatenate arrays of euch sublists in python

I have a list of numpy arrays and want to firstly split the list and then concatenate all the arrays exiting in each sublist. Number of sublists is defined by: n_sublist=2 # but in reality I have much …

Jupyter-notebook failed to import python packages

I was trying to use numpy in Jupyter Notebook in a Python3 virtual environment, but the encountered an error. In terminal, I did: $ python3 -m venv py3env $ source py3env/bin/activate (py3env)$ …

Plotting average linear regression of data set consisting of missing values

import matplotlib.pyplot as plt import pandas as pd import numpy as np from sklearn.linear_model import LinearRegression col1 = [2011.005, 2012.6543, 2013.3456, 2014.7821, 2015.3421, 2016.7891, 2017….

python transform 1d array of probabilities to 2d array

I have an array of probabilities: l = [0.9, 0.2, 0.4] and I want to make it 2d array: l = [0.9 0.1 0.2 0.8 0.4 0.6] What is the best way to do so? Thanks!

how to find perpendicular projection of point on a surface in python

I have a bunch of points in 3d space (x,y and z) and want to find their perpendicular projection on a surface in python. My surface is created by four points using the following function: PRECISION = …