[問題] Python語法問題請益

看板Python作者 (無傷大雅)時間6年前 (2019/05/02 02:06), 6年前編輯推噓1(106)
留言7則, 3人參與, 6年前最新討論串1/1
小弟最近在學Python, 實際應用需要修改網上的範例, 其中看到一段程式碼無法理解, 希望板上先進能協助,謝謝。 detections = [] detections = [Detection(bbox, score, feature) for bbox,score, feature in zip(detections, track_scores, features)] 1.detections List的第一個元素中有for,後面帶有bbox,score, 不曉得這是什麼意思@@? 實際在跑偵錯模式時,此行程式碼會進入數次。這個for 2.第二個元素中.. feature in這是什麼意思呢? 謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.230.200.240 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1556733983.A.566.html

05/02 02:11, 6年前 , 1F
關鍵字:list comprehension
05/02 02:11, 1F

05/02 02:12, 6年前 , 2F
for bbox,score, feature in zip(detections, track_s...
05/02 02:12, 2F

05/02 02:12, 6年前 , 3F
detections.append(Detection(bbox, score, feature)
05/02 02:12, 3F

05/02 02:12, 6年前 , 4F
有點像以上的code
05/02 02:12, 4F

05/02 02:30, 6年前 , 5F
謝謝crazycy大,完全看懂了^^
05/02 02:30, 5F
另有一個問題想請問,某段程式呼叫了_match函式,追蹤到_match後, 發現裡面又定義了一個函式,而這些函式參數完全不曉得是哪裡來的@@ _match只有detections這個引數阿... 再麻煩板友解惑,謝謝了.. def _match(self, detections): def gated_metric(tracks, dets, track_indices, detection_indices): features = np.array([dets[i].feature for i in detection_indices]) targets = np.array([tracks[i].track_id for i in track_indices]) cost_matrix = self.metric.distance(features, targets) cost_matrix = linear_assignment.gate_cost_matrix( self.kf, cost_matrix, tracks, dets, track_indices, detection_indices) return cost_matrix # Split track set into confirmed and unconfirmed tracks. confirmed_tracks = [ i for i, t in enumerate(self.tracks) if t.is_confirmed()] unconfirmed_tracks = [ i for i, t in enumerate(self.tracks) if not t.is_confirmed()] ※ 編輯: james999 (36.230.200.240), 05/02/2019 02:33:36

05/02 02:57, 6年前 , 6F
要去看 linear_assignment.py
05/02 02:57, 6F

05/02 16:21, 6年前 , 7F
謝謝art1大 :)
05/02 16:21, 7F
文章代碼(AID): #1SoU0VLc (Python)
文章代碼(AID): #1SoU0VLc (Python)