Skip to content

Commit 4e91313

Browse files
committed
HACK: add diag_indices helper for numpy < 1.4.0
Use of diag_indices causing error for numpy < 1.4.0; replicate in private function. Sometime soon after the release of Debian Wheezy as stable, we should drop numpy 1.3.0 compatibility and delete this helper.
1 parent e14dbaa commit 4e91313

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

nipy/algorithms/segmentation/segmentation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def set_markov_prior(self, beta, U=None):
106106
self.U = np.asarray(U).copy()
107107
else: # Potts model
108108
U = np.ones((self.nclasses, self.nclasses))
109-
U[np.diag_indices(self.nclasses)] = 0
109+
U[_diag_indices(self.nclasses)] = 0
110110
self.U = U
111111
self.beta = float(beta)
112112

@@ -206,6 +206,13 @@ def free_energy(self, ppm=None):
206206
return f1 + f2
207207

208208

209+
def _diag_indices(n, ndim=2):
210+
# diag_indices function present in numpy 1.4 and later. This for
211+
# compatibility with numpy < 1.4
212+
idx = np.arange(n)
213+
return (idx,) * ndim
214+
215+
209216
def moment_matching(dat, mu, sigma, glob_mu, glob_sigma):
210217
"""
211218
Moment matching strategy for parameter initialization to feed a

0 commit comments

Comments
 (0)