[SciPy-dev] Type handling of matrices

Pearu Peterson pearu at scipy.org
Wed Nov 17 03:49:02 CST 2004



On Wed, 17 Nov 2004, Nils Wagner wrote:

> Pearu Peterson wrote:

>> Anyway, by using
>> 
>> def gap(A)
>>  w = linalg.eigvals(A)
>>  mn = abs(w[0]-w[1])
>>  for i in range(len(w))
>>   for j in range(i):
>>      mn = min(mn,abs(w[i]-w[j]))
>>  return mn/2
>> 
>> should give speedup 2x at least.
>> 
>> Pearu
>> 
> And how can I return the associated indices \bar{i}, \bar{j} with respect to 
> gap(A) ?

def gap(A):
  w = linalg.eigvals(A)
  l = [(abs(w[i]-w[j]),j,i) for i in range(len(w)) for j in range(i)]
  l.sort()
  return l[0]

Pearu




More information about the Scipy-dev mailing list