【问题标题】:ValueError: object too deep for desired array (netcdf)ValueError:对象对于所需数组来说太深(netcdf)
【发布时间】:2016-02-09 10:02:58
【问题描述】:

我正在尝试将 SIFT 功能传递给 netcdf 文件,但是当我尝试这样做时,它显示我出现以下错误(我使用的是 Ubuntu 15.10 并在 python 中编码)。

文件“/home/Research/netcdf_helpers.py”,第 15 行,在 createNcVar nc_var.assignValue(data) ValueError: object too deep for desired array

我搜索了各种解决方案,但仍然找到了正确的解决方案。

我的数据结构的当前格式如下:

[[(file1feature1,file1feature2,file1feature3,file1feature4,file1feature5),(file2feature1,file2feature2,file2feature3,file2feature4,file2feature5)(file3feature1,file3feature2,file3feature3,file3feature4,file3feature5)]]

我希望实现的期望输出如下:

[file1feature1,file1feature2,file1feature3,file1feature4,file2feature5,file2feature1,file2feature2,file2feature3,file2feature4.......]

我已经用了半天​​时间来纠正这个错误,但仍在苦苦挣扎。任何帮助将不胜感激。

【问题讨论】:

  • 关于所需的输出,您是否需要对列表进行排序,如果是,是否完全按照上面指定的方式?
  • 实际上,我需要图像中的特征值,而不是要排序的列表。
  • 下面的答案,是否达到了你想要的输出?

标签: python list netcdf sift


【解决方案1】:

示例:

为了模仿您的数据结构,我使用了以下数据:

raw_data = [[(1, 2, 3), (9, 8, 7), (5, 6, 0)]]]  # this is the raw data

下面的操作就得到了你想要的结构:

data = () # place holder for your filtered data

for entry in raw_data[0]:  # operation
    data += entry

输出:

print(list(data)) # [1, 2, 3, 9, 8, 7, 5, 6, 0]

【讨论】:

  • 提取SIFT特征的语句如下, temp = (point.size, point.angle, point.response, point.octave, point.class_id) 如果我取30个SIFT关键点那么对于每个关键点,temp 将记录 5 个特征点并分配给 temp。之后,我将附加一个本地列表。全局列表附加了本地列表值,对于下一张图像,本地列表最初将为空。
  • 上面的代码应该将该操作的原始输出转换为您在原始帖子中声明的所需输出。
  • 感谢您的帮助,但这不是我正在寻找的实际解决方案。我不确定数据[][],因为我使用的是庞大的数据集。我希望通用解决方案不特定于数组的元素。无论我想要数组中有多少元素 [1,2,3,4,5,6,7....]
  • github.com/jpuigcerver/rnnlib/blob/master/utils/… 在这个文件中,第 30 行给我的代码带来了问题。我传递了该文件所需的所有值,但是当我将特征值传递给它时,我遇到了上面提到的错误。
  • 最初的解决方案是通用的。编辑版本独立于无。行数据中的元素数量。
猜你喜欢
  • 2017-01-21
  • 2012-10-28
  • 1970-01-01
  • 2019-04-03
  • 2018-07-17
  • 2019-10-19
  • 1970-01-01
  • 1970-01-01
  • 2019-01-02
相关资源
最近更新 更多