3D numpy array threshold comparison

I’m trying to solve whether or not each element in a 3d numpy array fits within a certain threshold. Currently I have nested for loops that get the job done, but it’s really slow and I don’t have all …

Conditional formatting of arrays in Numpy Python

I am trying to make a function where if the last value of order is 1 then the code will append 1 to orders and then append the number 20 to the value array as well. If the last value is 0 in order …

How to using numpy.argsort on a 2D array to sort another 2D array

I use numpy.argsort all the time for 1D data, but it seems to behaving differently in 2D. For example, let’s say I want to argsort this array along axis 1 so the items in each row are in ascending …

sum the elements of 2 NumPy arrays

import numpy as np n1=np.array([10,20,30,40,50,60]) n2=np.array([50,60,70,80]) np.sum([n1,n2]) ValueError Traceback (most recent call last)

Why is my conical/angle gradient image distorted?

I’m currently trying to create a conical gradient, and it kind of works. However, it doesn’t look quite right and I can’t wrap my hand around to why: The line that goes up from the center is slightly …

Pandas average of previous rows fulfilling condition

I have a huge data-frame (>20m rows) with each row containing a timestamp and a numeric variable X. I want to assign a new column where for each row the value in this new column is the average of X …

Appending to empty array in a for loop (python)

How do I append values in an empty numpy array? I have an array of values that I want to perform a mathematical equation on and from those values I want to append it to a new empty array. What I have …

How to replace equal consecutive numbers in a list to nan?

I’m trying to replace equal consecutive numbers in a list to nan. I having problems to replace all values when there is a odd number of equal consecutive numbers. This is my code, very simple: list= […

Optimizing a standard deviation function Pandas Numpy Python

The std pandas function below calculates the standard deviation of every nth value defined by number. So it would take the the values of PC_list with indexes [0,1,2,3,4,5] and calculate the standard …

Can I use numpy.polyfit(x, y, deg) for multiple linear regression

Is there any way I can fit two independent variables and one dependent variable in numpy.polyfit()? I have a panda data frame that I loaded from a csv file. I wish to include two columns as …