python - 在python中获取对象数组的属性作为数组

标签 python arrays

我在 python 中创建了一个类,如下

class Member:
    def __init__(self, kalmanBoxTracker):
        self.member_id = kalmanBoxTracker.id
        self.member_area = kalmanBoxTracker.kf.x[2]

然后我创建了这个对象的数组,如下所示:

for trk in trackers:
   ret_mem.append(Member(trk))

如何获取 ret_mem 数组的 member_area 属性作为数组?

最佳答案

试试这个:

member_areas = [m.member_area for m in ret_mem]

关于python - 在python中获取对象数组的属性作为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61245844/

相关文章:

C - 使用动态数组

python - 尝试在 h5py : ValueError: Unable to set extend dataset (Dimension cannot exceed the existing maximal size 中扩展现有数据集时出错

python - 如何将图形(3x3 子图)插入 matplotlib python 的子图中

javascript - 为什么在 for 循环中使用 pop() 不起作用 (javascript)

java - 如何清除 JSON 数组中的数据

python - 值错误 : The elements are 0-sized

python - 全局变量的使用

Python数据框: Randomly delete rows with initial condition

python - PyQt QDialog - 返回一个值并从对话框中关闭

c - 如何定义一个全局数组(获取另一个函数的长度)?