簡體   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