Python:检查表中的值在其他表中的位置

时间:2017-03-13 13:07:32

标签: python

[编辑]我想用Python解决这个问题:我有一个列出一些点坐标的表,所以它有两列A,B。另一个表列出了两列C,D中点的坐标。 col C和D中的值与A和B中的值相同,但它们的顺序不同。我的目的是检查A,B中的值在C,D列中的位置。 我试过这段代码:[抱歉,我只放了一部分代码,但现在已经完成了]

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'

但输出没有出现......代码卡在if语句中。你能帮助我吗?谢谢:))

输出错误:

[array([ 0.,  0.,  0.]), array([ -9.19361118e-02,  -5.62946325e-18,  -9.95764908e-01]), array([ 0.,  0.,  0.]), array([  9.19361118e-02,   5.62946325e-18,   9.95764908e-01])]
[array([ -4.02455846e-16,  -2.46433132e-32,  -1.00000000e+00]), array([  4.02455846e-16,   2.46433132e-32,   1.00000000e+00]), array([ 0.,  0.,  0.]), array([ 0.,  0.,  0.])]
[array([ -1.32548132e-01,  -8.11623230e-18,   5.20417043e-17]), array([  6.07243954e-01,   3.71829682e-17,  -4.38273008e-02]), array([ 0.,  0.,  0.]), array([ -4.74695821e-01,  -2.90667359e-17,   4.38273008e-02])]
[array([  9.89550969e-01,  -1.21185043e-16,  -1.44183494e-01]), array([ 0.,  0.,  0.]), array([ -9.89550969e-01,   1.21185043e-16,   1.44183494e-01]), array([ 0.,  0.,  0.])]
[array([ -6.17327484e-02,   7.56008127e-18,   4.86015631e-01]), array([  1.32548132e-01,  -1.62324646e-17,  -0.00000000e+00]), array([ -7.08153840e-02,   8.67238333e-18,  -4.86015631e-01]), array([ 0.,  0.,  0.])]
[array([  5.84181997e-17,  -9.58615055e-01,  -0.00000000e+00]), array([  2.36516717e-18,   6.64023184e+00,   0.00000000e+00]), array([ -6.07833668e-17,  -4.96333856e-01,   0.00000000e+00]), array([ 0.        , -5.18528293,  0.        ])]

1 个答案:

答案 0 :(得分:0)

我无法弄清楚你的代码,因为它缺少一些东西但是对于初学者可能会尝试删除这里的括号:

if (item2 >= tuple(np.subtract(item1,delta))) and (item2<=tuple(np.sum(item1,delta))):
像那样:

if item2 >= tuple(np.subtract(item1,delta)) and item2 <=  tuple(np.sum(item1,delta)):

您不需要将每个条件都放在python中的括号内。