我试图计算温度趋势
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几天,任何人都可以帮助我,谢谢
答案 0 :(得分:0)
当您通过ny
zeros ndarray创建nx
时,您可以指定要在其中存储哪种类型的元素。如果要在零数组的每个单元格中存储1x2浮点值数组(polyfit with degree = 1,返回1x2浮点数组),则可以选择以下类型而不是float
:
trend = numpy.zeros((ny,nx), dtype='2f')
之后,您可以轻松地存储数组,作为trend
ndarray