I am running a code that could potentially benefit from different initialization(s) of random number generators. I use libraries torch and python. I am using the following lines of code to set random seed at the beginning of every iteratio…
import numpy as np
a5 = np.array[[1 2 3],[4 5 6]]
a = len(a5) # rows of a5
b = len(a5) # columns of a5
a6 = np.zeros([b, a])
for i in range(len(a5)):
for j in range(len(a5)):
a6[i][j] = a5[j]…
I use the long list of codes similar to below codes, to check data frame with multiple columns
I need to check if the column has any values greater than Eg. 1000. If >1000 its error value, so make it ‘0’
a = np.array(df[‘E8’].val…
I have two HxW matrices A and B. I’d like to get an NxHxW matrix C such that C=A, C[-1]=B, and each of the remaining N-2 slices are linearly interpolated between A and B. Is there a single numpy function I can do this with, without need…
The code down below goes through the Vals function and it assorts through the Numbers value and adds up all the sums after the sorting. I am trying to append the SUM values to the T_SUM to store the values of each SUM for each sort.
I am trying to create a mask to compare two arrays A2 and A5 that have the same size and number of elements.
My professor wants the following: If the element in A1’s first column is positive, show elements in A2 at the same row as that el…
I want to run a for loop with index i so that I can define (inside each loop) an ndarray with name A_i. More concretely, I want it to look something like
for i in range(numer):
A_i = M
where M is some ndarray that was defined in a pre…
I’m trying to create a list of random variables wtfuns that I can call as: wtfuns[i](size=1000) to return a list of 1000 samples of the particular random variable. For this, I am using lambda functions as follows:
wtfuns = 
pvals = [0.3,…
I am trying to find the mask for the maximum value in every 2×2 block in a 2d array (for max pooling backpropagation in a CNN).
[[ 0 1 4 0]
[ 4 2 3 3]
[ 2 0 3 2]
[ 0 1 5 1]]
Needs to become:
[[ 0 0 1 0]
[ 1 0 …
I am working on a project and have a thousands of synthetically generated circles. But now I want to generate a heatmap with highest probability at the center as it decays to zero I go further to the perimeter. I used the openCV’s circle()…
I have some simulation data that should be binned into a histogram (binning with sum).
The original data is shown in the figure below. The blue dots are the data to be binned, the red lines are the logscale grids that define th…
I am building an array of coordinates from multiple d-dimensional cubes. I would like to start with an empty array and append the coordinates that I generate in each for-loop. However, np.concatenate (and vstack) requires an existing array…
I am trying to merge two dataframes together.
This is my main dataframe which has a row of BillingPostalCodes
In another table are Segments stored based on the BillingPostalCode.
If I merge b…
I want to add all nonzero elements from a numpy array arr to a list out_list. Previous research suggests that for numpy arrays, using np.nonzero is most efficient. (My own benchmark below actually suggests it can be slightly improved using…
I want to vectorize an operation, and I cannot figure out how to optimize it.
Say I have a 3D array a of shape (4, 6, 3). I want to sum the consecutively non-nan values over axis 0, and compute the maximum of the newly formed array b over …
Here is the code:
width_image = image.shape
height_image = image.shape
width_shape = new_shape
height_shape = new_shape
startx = math.ceil((width_image – width_shape)/2)
starty = math.ceil((height_image – height_shape)/…
I’m attempting a complex transformation to an image, where, for simplicities sake, a new image is created where every pixel at location (x, y) is defined as the location (X(x), Y(x)) in the original image, where X() and Y() are the functio…
I have the given sample data and interpolated spline:
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
x = [0.1,1.5,2.3,5.5,6.7,7]
y = [5,4,5,2,2,3]
s = interpolate.UnivariateSpline(x, y, s=0)
xs = np.lins…
I am using the following to compare several strings to each other. It’s the fastest method I’ve been able to devise, but it results in a very large 2D array. which I can look at and see what I want. Ideally, I would like to set a threshol…
I have a dataframe (df) with the following columns:
And let’s assume all the columns have numbers as data.
Then I select some of the columns to become indexes
Index = [‘A’,’B’,’C’]