遇到“TypeError: only size-1 arrays can be converted to Python scalars”,按照网上的不太行,一直会报错,而且和他们的报错都不一样:

  1. 显示运行后报这样:

解决“TypeError: only size-1 arrays can be converted to Python scalars”_scala

  1. 然后结束时候是这样:

解决“TypeError: only size-1 arrays can be converted to Python scalars”_debug_02

看着好生奇怪,后面用list搞了下可以了,下面这样额额额:

list_t = []
if nums.dtype == np.object:
    for seq in nums:
        seq = seq.reshape(39)
        list_t.append(seq)
    nums = np.array(list_t)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.