#### Category : numpy-ndarray

I’m making an interface between Python and Fortran code with Cython. One part of that is retrieving arrays of strings. In Fortran, character(len=3) :: str_array(:) For the sake of this example, suppose str_array contains the following allocate(str_array(2)) str_array = [‘abc’,’def’] My approach is to return this to Cython as a single C char array. I ..

I want to calculate powerset of 1-dim array using numpy, sckit-learn of whatever is the fastest approach. By fast approach i mean, something that will take less that 9 seconds, even when the length of the input is 200000. This code below does the trick. But it is too slow. from itertools import chain, combinations ..

I am generating two parameters e.g. s1 = [0, 0.25, 0.5, 0.75, 1.0] s2 = [0, 0.25, 0.5, 0.75, 1.0] based on dimensions of both these lists above, i am creating a grid of zeros: np.zeros((5,5)) I then pair up each of the numbers in each list so they form coordinate locations in my empty ..

I have a 3D NumPy array of size (9,9,200) and a 2D array of size (200,200). I want to take each channel of shape (9,9,1) and generate an array (9,9,200), every channel multiplied 200 times by 1 scalar in a single row, and average it such that the resultant array is (9,9,1). Basically, if there ..

Lets assume we have got the matrix M = np.array([[1,2,3],[4,5,6],[7,8,9]]). I want to create a new row that conclumerates row number 1 and row number 2. So the output should be [2.5, 3.5, 4.5]. To compute the mean between rows 1 and 2 I tried: np.mean(M[0:2,:]) which returns 3.5 as the scalar mean of both .. I want to fit 2 models (linear, parabolic) to the following data. What I have done is fitting it on both sites seperately by cutting the x-array (label s) and the data in half using: log_powspec_gal_tem_1 = np.log(powspec_gal_tem)[s>=0] log_powspec_gal_tem_2 = np.log(powspec_gal_tem)[s<0] s_1 = s[s>=0] s_2 = s[s<0] The problem with that is as you can ..

I am sitting on a weird problem. I have two things, m and mhat: m [[1 0 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 0 0 ..

For a course I’m doing we are given a timeseries dataset with one array being observations of velocity. The task is to design a while loop that finds the median of an odd-numbered window around a given point, for each observation, and make a new array of the same length with the observations replaced by .. 