一個相當簡單的問題,但我似乎沒有找到任何解決方案:用numpy數組填充數組?
我想在數組中使用兩個數組的差異,並將其作爲新的結果插入到一個新的數組中......我希望代碼澄清這個意圖,儘管它不工作,因爲python告訴我它不能將序列與數組計算結合起來......我該如何解決這個問題?提前致謝!
MeteorNum = 5
#Coordinate Setup:
XPos = np.random.randint(0, 600, (MeteorNum,1))
YPos = np.random.randint(0, 800, (MeteorNum,1))
XYPos = np.hstack((XPos,YPos))
XYPos = np.vstack((XYPos, XYPos[0]))
print XYPos
#Distances:
r = np.zeros((MeteorNum,MeteorNum))
for i in range(0, MeteorNum):
for x in range(0, MeteorNum):
r[x,i] = (XYPos[x,:] - XYPos[i,:])
r = r*10**5
print r
,並在這裏的錯誤,我得到:
runfile('C:/Users/Marco DS/Dropbox/1_TUDelft/4Q/AE1205 Python/python codes 2015/bonus assigments/week_5 Gravity simu.py', wdir='C:/Users/Marco DS/Dropbox/1_TUDelft/4Q/AE1205 Python/python codes 2015/bonus assigments')
[[249 660]
[256 605]
[119 423]
[422 398]
[480 504]
[249 660]]
Traceback (most recent call last):
File "<ipython-input-57-4cd9cc29ece0>", line 1, in <module>
runfile('C:/Users/Marco DS/Dropbox/1_TUDelft/4Q/AE1205 Python/python codes 2015/bonus assigments/week_5 Gravity simu.py', wdir='C:/Users/Marco DS/Dropbox/1_TUDelft/4Q/AE1205 Python/python codes 2015/bonus assigments')
File "C:\Users\Marco DS\Anaconda\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 682, in runfile
execfile(filename, namespace)
File "C:\Users\Marco DS\Anaconda\lib\site- packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/Marco DS/Dropbox/1_TUDelft/4Q/AE1205 Python/python codes 2015/bonus assigments/week_5 Gravity simu.py", line 37, in <module>
r[x,i] = (XYPos[x,:] - XYPos[i,:])
ValueError: setting an array element with a sequence.
請顯示所有錯誤... – plonser
更好嗎? – user3604362
請顯示完整的錯誤信息(回溯),它應該有一個行號,它被卡住的行,函數名稱,模塊名稱,... –