繁体   English   中英

__ValueError:使用序列设置数组元素

[英]__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零ndarray创建ny ,可以指定要存储在其元素中的类型。 如果要在float数组的每个单元格中存储1x2浮点值数组(度数为1的polyfit返回1x2浮点数组),则可以选择以下类型来代替float

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM