MATLAB gives error while running a good Python code: TypeError: 'float' object is not iterable
Afficher commentaires plus anciens
I am trying to run an averaging code that requires a list and a single number tau. The python code runs well in Python 3.5.3 with inputs for eg. average([[12,13,14],[24,26,28]],0.5). The python code is as follows:
from math import *
def average(spike_trains,tau):
class Delta_error:
def __init__(self,spike_trains,tau):
self.n=len(spike_trains)
self.big_train=[]
for train in spike_trains:
self.big_train=self.big_train + train
#print(self.big_train)
#self.big_train.append(train)
self.centre_train=[]
self.tau=tau
self.min=min(self.big_train)
self.max=max(self.big_train)
def add_spike(self,time):
self.centre_train.append(time)
def minimize(self):
value=1.0
time=self.min
for spike in self.big_train:
new_value=self.__call__(spike)
if new_value<value:
value=new_value
time=spike
return time
def sort(self):
self.centre_train.sort()
delta_error=Delta_error(spike_trains,tau)
train_length=len(delta_error.big_train)//len(spike_trains)
for spike_c in range(0,train_length):
new_spike = delta_error.minimize()
delta_error.add_spike(new_spike)
delta_error.sort()
return delta_error.centre_train
Answer: [13, 24, 26]. In python.
When running in MATLAB running Python 3.5.3 (from pyversion)
py.average.average([[12,13,14],[24,26,28]],0.5)
I get the following vague error:
Python Error: TypeError: can only concatenate list (not "float") to list
The bolded lines have been problematic in MATLAB, but after changing the version of python running in MATLAB, I am only getting a one line error.
I need this code to work in MATLAB. What should I do? I would appreciate all tips and suggestions!
2 commentaires
Kojiro Saito
le 7 Août 2019
Could you show us "__call__" definition in your Python scripts?
Ritwika Mukherjee
le 7 Août 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Call Python from MATLAB dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!