TypeError:在python中,类型为“numpy.float64”的对象没有len()

s5a0g9ez  于 2023-03-08  发布在  Python
关注(0)|答案(1)|浏览(420)

我是Python新手,所以我尝试使用以下代码调用ELM(position)函数来进行迭代:

def fitness(positon):
  for i in range(len(position[0])):
    acc[i] = ELM(position[i])
  return acc
acc = fitness(position)
print(acc)

但是当我运行时,出现如下错误:

> > --------------------------------------------------------------------------- TypeError                                 Traceback (most recent call last)
    > > <ipython-input-32-b5817c120096> in <module> 3     acc[i] = ELM(position[i]) 
4   return acc 
5 acc = fitness(position) 
6 print(acc)
    
    2 frames
    > > <ipython-input-31-f7fd3cdc85c5> in matriks_kali(xtrain, transpose) 
5  
6 def matriks_kali(xtrain, transpose): 
7   kaliHinittrain = np.zeros((len(xtrain), len(transpose[0]))) 
8   for i in range(len(xtrain)): 
9     for j in range(len(transpose[0])):
   
    TypeError: object of type 'numpy.float64' has no len()
zkure5ic

zkure5ic1#

position可能是您尝试迭代的对象列表。请尝试删除position[0],然后查找len(position)

def fitness(positon):
  for i in range(len(position)):
    acc[i] = ELM(position[i])
  return acc
acc = fitness(position)
print(acc)

相关问题