我試圖找到一個交集組兩個位置列表,在ROS不能使用Python交叉口ROS點列表設置
,所以我用Python語言編寫代碼,我有兩個列表,如:
position1 = Point()
position1.x =1
position2 = Point()
position2.x=2
a = [copy.deepcopy(position1),copy.deepcopy(position2)]
b = [copy.deepcopy(position1)]
然後,當我試圖讓這兩個列表A和b
的交集還給我一個答案:集([])
這是荒謬的,
通常我應該有這樣一個答案:集(一).intersection(組(B))=集合([位置1])
如果有人可以幫我解決這個問題?
這是偉大的感謝觀看這個問題
,我很欣賞你的觀看和應答。
在此先感謝。
這裏是我的測試代碼
import rospy,copy
from geometry_msgs.msg import Point
class test():
def __init__(self):
position1 = Point()
position1.x =1
position2 = Point()
position2.x=2
a = [copy.deepcopy(position1),copy.deepcopy(position2)]
b = [copy.deepcopy(position1)]
print set(a).intersection(set(b))
print 'a', set(a),'\n'
print 'b', set(b)
if __name__=='__main__':
try:
rospy.loginfo ("initialization system")
test()
rospy.loginfo ("process done and quit")
except rospy.ROSInterruptException:
rospy.loginfo("robot twist node terminated.")
BTW,ROS點類型張貼在這裏:http://docs.ros.org/jade/api/geometry_msgs/html/msg/Point.html
它沒有看到它如何返回'set([])',顯示所有的代碼。 – polku
感謝您的回答,我寫了一個測試代碼,並在我的問題結尾附上 – HOWE
'set's依靠'hash'和'=='來工作...是'hash(position1)'與'散列(position2)'並且'position1 == position2'評估爲'True'? –