【问题标题】:Is there any way to iterate through Orange table in python script?有没有办法在 python 脚本中遍历 Orange 表?
【发布时间】:2021-03-09 11:38:03
【问题描述】:

以下是将图片导入Orange的代码,导入的图片列表存储在Orange表中:

import Orange
from orangecontrib.imageanalytics.import_images import ImportImages
import_images = ImportImages()
data, err = import_images("E:/CME/CME3/Project Work/domestic-animals")    
if data:
    print(data)
    print(err)
    print(type(data))

导入的图像以表格形式存储在数据变量中。

输出:

>>> 
Running script:
[[] {calf, calf.png, 45538, 191, 152},
 [] {cat, cat.png, 22193, 105, 137},
 [] {chick, chick.png, 14891, 85, 92},
 [] {cow, cow.png, 62159, 210, 189},
 [] {crow, crow.jpg, 6778, 259, 194},
 [] {dog, dog.png, 28745, 129, 125},
 [] {duck, duck.png, 39583, 158, 172},
 [] {duckling, duckling.png, 17109, 99, 119},
 [] {foal, foal.png, 39210, 147, 177},
 [] {goat, goat.png, 53039, 221, 179},
 [] {goose, goose.png, 34442, 141, 202},
 [] {hen, hen.png, 41716, 134, 168},
 [] {horse, horse.png, 69109, 285, 195},
 [] {kid, kid.png, 36290, 170, 160},
 [] {lamb, lamb.png, 35520, 123, 168},
 [] {Milka, Milka.jpg, 111090, 533, 800},
 [] {ox, ox.png, 56401, 191, 189},
 [] {rabbit, rabbit.png, 24294, 97, 174},
 [] {rooster, rooster.png, 41518, 145, 180},
 [] {sheep, sheep.png, 58022, 214, 181},
 [] {turkey, turkey.png, 55072, 171, 182}]
0
<class 'Orange.data.table.Table'>
>>> 

数据变量是表类型。 我想访问 .png 文件的列。如何遍历上表? 我尝试使用 for 循环进行迭代:

for i in range(len(data)):
    files = data[i][1]

但是我收到了这个错误:

IndexError: index 1 is out of bounds for axis 0 with size 0

提前谢谢你。

【问题讨论】:

  • 您是否尝试过查看tutorialAPI reference 的相关部分?
  • 是的,我完成了教程。好吧,我找到了方法。它现在正在工作
  • 欢迎回答你自己的问题。 ??????

标签: python data-mining orange


【解决方案1】:

在每个 RowInstance (data[i]) 中,您可以通过 metas 调用这些项目 ({...})。

见:https://orange3.readthedocs.io/projects/orange-data-mining-library/en/latest/reference/data.instance.html

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
  • 伊万是对的。其他选项是简单地遍历元数据:for i in data.metas:
猜你喜欢
  • 1970-01-01
  • 2021-07-14
  • 1970-01-01
  • 1970-01-01
  • 2010-11-20
  • 2010-10-06
  • 1970-01-01
  • 1970-01-01
  • 2016-01-16
相关资源
最近更新 更多