Get coordinates of local maxima in 2D array above certain value

import numpy as np import scipy import scipy.ndimage as ndimage import scipy.ndimage.filters as filters import matplotlib.pyplot as plt fname=”/tmp/slice0000.png” neighborhood_size = 5 threshold = 1500 data = scipy.misc.imread(fname) data_max = filters.maximum_filter(data, neighborhood_size) maxima = (data == data_max) data_min = filters.minimum_filter(data, neighborhood_size) diff = ((data_max – data_min) > threshold) maxima[diff == 0] = 0 labeled, num_objects … 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

Concatenate sparse matrices in Python using SciPy/Numpy

You can use the scipy.sparse.hstack to concatenate sparse matrices with the same number of rows (horizontal concatenation): from scipy.sparse import hstack hstack((X, X2)) Similarly, you can use scipy.sparse.vstack to concatenate sparse matrices with the same number of columns (vertical concatenation). Using numpy.hstack or numpy.vstack will create an array with two sparse matrix objects.

tech