Downsample array in Python

scikit-image has implemented a working version of downsampling here, although they shy away from calling it downsampling for it not being a downsampling in terms of DSP, if I understand correctly: http://scikit-image.org/docs/dev/api/skimage.measure.html#skimage.measure.block_reduce but it works very well, and it is the only downsampler that I found in Python that can deal with np.nan in the … Read more

Reverse Box-Cox transformation

SciPy has added an inverse Box-Cox transformation. https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.inv_boxcox.html scipy.special.inv_boxcox scipy.special.inv_boxcox(y, lmbda) = Compute the inverse of the Box-Cox transformation. Find x such that: y = (x**lmbda – 1) / lmbda if lmbda != 0 log(x) if lmbda == 0 Parameters: y : array_like Data to be transformed. lmbda : array_like Power parameter of the Box-Cox … Read more

How to select inverse of indexes of a numpy array?

mask = np.ones(len(data), np.bool) mask[sample_indexes] = 0 other_data = data[mask] not the most elegant for what perhaps should be a single-line statement, but its fairly efficient, and the memory overhead is minimal too. If memory is your prime concern, np.delete would avoid the creation of the mask, and fancy-indexing creates a copy anyway. On second … Read more

scipy is not optimizing and returns “Desired error not necessarily achieved due to precision loss”

I copied your example and tried a little bit. Looks like if you stick with BFGS solver, after a few iteration the mu+ alpha * r will have some negative numbers, and that’s how you get the RuntimeWarning. The easiest fix I can think of is to switch to Nelder Mead solver. res = minimize(loglikelihood, … Read more

Fitting a 2D Gaussian function using scipy.optimize.curve_fit – ValueError and minpack.error

The output of twoD_Gaussian needs to be 1D. What you can do is add a .ravel() onto the end of the last line, like this: def twoD_Gaussian(xy, amplitude, xo, yo, sigma_x, sigma_y, theta, offset): x, y = xy xo = float(xo) yo = float(yo) a = (np.cos(theta)**2)/(2*sigma_x**2) + (np.sin(theta)**2)/(2*sigma_y**2) b = -(np.sin(2*theta))/(4*sigma_x**2) + (np.sin(2*theta))/(4*sigma_y**2) c … Read more