-1
[編輯]我想用Python解決這個問題:我有一個表列出了一些點的座標,所以它有兩列A,B。表列出了C,D兩列中點的座標。列C和D中的值與A和B中的值相同,但它們的順序不同。我的目的是檢查A,B中的值在C,D列中的哪個位置。 我試過這段代碼:對不起,我只把一部分代碼,但現在它是完整]Python:檢查表中的值在其他表中
import pyfits
from nifty import *
hdulist = pyfits.open('PolCat_withRRM.fits')
tbdata = hdulist[1].data
G_lon = np.array(tbdata.field('G_lon'))
G_lat = np.array(tbdata.field('G_lat'))
np.save('glon', G_lon)
np.save('glat', G_lat)
matrix=[G_lon,G_lat]
matrice=np.array(matrix)
#loading information about the sources and the (simulated) data
lon = np.load('lon.npy')
lat = np.load('lat.npy')
#Now I want know where the values in colujmns G_lon e G_lat are in lon e lat columns
delta=(0.003,0.003)
for item1 in zip(G_lon, G_lat):
for item2 in zip(lon, lat):
if (item2 >= tuple(np.subtract(item1,delta))) and (item2 <= tuple(np.sum(item1,delta))):
item2_index=np.where(lon)
item = lon[item2_index]
print item2
但產量不會出現...該代碼是停留在if語句。你可以幫我嗎?謝謝:)
的輸出是一個錯誤:
ValueError Traceback (most recent call last)
<ipython-input-2-eeb8c31b51d3> in <module>()
----> 1 execfile('PolCat_withRRM.py')
72 for item2 in zip(lon, lat):
73 #for i in G_lon:
---> 74 if item2 >= tuple(np.subtract(item1,delta)) and item2 <= tuple(np.sum(item1,delta)):
75 item2_index=np.where(lon)
76 item = lon[item2_index]
/usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.pyc in sum(a, axis, dtype, out, keepdims)
1833 except AttributeError:
1834 return _methods._sum(a, axis=axis, dtype=dtype,
-> 1835 out=out, keepdims=keepdims)
1836 # NOTE: Dropping the keepdims parameters here...
1837 return sum(axis=axis, dtype=dtype, out=out)
/usr/local/lib/python2.7/dist-packages/numpy/core/_methods.pyc in _sum(a, axis, dtype, out, keepdims)
30
31 def _sum(a, axis=None, dtype=None, out=None, keepdims=False):
---> 32 return umr_sum(a, axis, dtype, out, keepdims)
33
34 def _prod(a, axis=None, dtype=None, out=None, keepdims=False):
ValueError: duplicate value in 'axis'
感謝您的解決方案,但它不起作用。更好的是,輸出是我在問題中添加的錯誤.. – user23299