arrays - IDL - 数组结构到结构数组

标签 arrays struct idl fits

我从一个 FITS 表中读取数据,并获得一个包含该表的结构,其中每个标签代表一列。

有没有办法将数组结构重新格式化为结构数组? 那么 Array 中的一个 Struct 代表一行?


@mgalloy 提出的一般解决方案(见下文):

function SoA2AoS, table

  if (table eq !NULL) then return, !NULL

  tnames = tag_names(table)
  new_table = create_struct(tnames[0], (table.(0)[0]))
  for t = 1L, n_tags(table) - 1L do begin
    new_table = create_struct(new_table, tnames[t], (table.(t))[0])
  endfor

  new_table = replicate(new_table, n_elements(table.(0)))

  for t = 0L, n_tags(table) - 1L do begin
    new_table.(t) = table.(t)
  endfor

  return, new_table

end

最佳答案

是的,所以你有这样的东西?

IDL> table = { a: findgen(10), b: 2. * findgen(10) }

创建一个新表,定义单行的外观并将其复制适当的次数:

IDL> new_table = replicate({a: 0.0, b: 0.0}, 10)

然后将列复制过来:

IDL> new_table.a = table.a
IDL> new_table.b = table.b

您的新表可以按行或列访问:

IDL> print, new_table[5]
{      5.00000      10.0000}
IDL> print, new_table.a
  0.00000      1.00000      2.00000      3.00000      4.00000      5.00000      6.00000
  7.00000      8.00000      9.00000

关于arrays - IDL - 数组结构到结构数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29843854/

相关文章:

java - 多维数组/数组的数组列表的问题

c - C 中 undefined reference

C# 没有指定大小的数组

java - 如何使用 IDL 将对象作为参数传递

php - 将查询结果放入数组然后内爆?

php - 根据相关 id 列将第二个二维数组中的数据添加到第一个二维数组中

c - 有没有办法使用相同的函数对不同列表结构中的同一字段执行操作?

c++ - 在 idl 中使用 importlib 时,自动生成的 .tlh 中的编译器错误 C3646 'unknown override specifier'

java - Corba - 唯一用户 ID

arrays - 打印 True 或 False