__ValueError: setting an array element with a sequence

__ValueError: setting an array element with a sequence

我正在尝试计算温度趋势

ntimes, ny, nx = tempF.shape
print tempF.shape
trend = MA.zeros((ny,nx),dtype=float)

print trend.shape

for y in range (ny):
    for x in range(nx):
        trends[y,x] = numpy.polyfit(tdum, tempF[:,y,x],1)


print trend()

结果是

    (24, 241, 480)
    (241, 480)
 ValueErrorTraceback (most recent call last)
<ipython-input-31-4ac068601e48> in <module>()
     12 for y in range (0,ny):
     13     for x in range (0,nx):
---> 14         trend[y,x] = numpy.polyfit(tdum, tempF[:,y,x],1)
     15 
     16 

/home/charcoalp/anaconda2/envs/pyn_test/lib/python2.7/site-packages/numpy/ma/core.pyc in __setitem__(self, indx, value)
   3272         if _mask is nomask:
   3273             # Set the data, then the mask
-> 3274             _data[indx] = dval
   3275             if mval is not nomask:
   3276                 _mask = self._mask = make_mask_none(self.shape, _dtype)

ValueError: setting an array element with a sequence.

我刚用python几天,谁能帮帮我,谢谢

当您通过 nx zeros ndarray 创建 ny 时,您可以指定要在其元素中存储的类型。如果要在 zeros 数组的每个单元格中存储 1x2 浮点值数组(polyfit with degree=1 returns 1x2 浮点数组),您可以选择以下类型而不是 float

trend = numpy.zeros((ny,nx), dtype='2f')

之后,您可以轻松地将数组存储为 trend ndarray

的元素