【发布时间】:2017-10-20 11:53:52
【问题描述】:
我在python中有这段代码
data = np.empty(temp.shape)
maxlat = temp.shape[0]
maxlon = temp.shape[1]
print(maxlat,maxlon)
for i in range(0,maxlat) :
for j in range(0,maxlon):
data[i][j] = p_temperature(pr,temp[i][j])
当我在 Python 3.5 中运行此代码时,我收到此错误
ValueError : setting an array element with a sequence
maxlat 的值为181,maxlon 的值为360。
temp数组的形状是(181,360)
我也尝试了cmets中的建议:
for i in range(0,maxlat) :
for j in range(0,maxlon):
data[i][j] = temp[i][j]
但我得到了同样的错误。
【问题讨论】:
-
ptemperature是做什么的? -
根据错误,看起来
p_temperator没有返回一个标量,而是一个numpy数组本身。 -
@WillemVanOnsem - 它只返回一个给定两个输入 p 和 temp 的数字
-
在问题中。但是,请只是一个示例(例如 5x5 不是完整的 181x360),基本上足以让我们重现您的问题并帮助您解决它
-
@ADITYA 不,这会引发
ValueError: could not convert string to float:异常。 :)
标签: python arrays numpy python-3.5