我必须在我的Torch / Lua脚本中分析一些对象及其结构。
我想使用行为类似str()
in R的命令。
你有什么建议吗?
答案 0 :(得分:2)
您可能希望使用serializer以可读的方式表示复杂的数据结构。有torch.serialize功能,但它不会产生人类可读的输出。我写了Serpent serializer and pretty-printer支持str()
的一些选项,例如表格的最大嵌套级别或表格中的最大元素数量。它还支持自定义格式化程序,允许您在一定程度上修改输出。
答案 1 :(得分:0)
我喜欢这个模块:https://github.com/kikito/inspect.lua
luarocks install inspect
然后像这样导入
local inspect = require 'inspect'
输出可能是这样的:
assert(inspect(setmetatable({a=1}, {b=2}) == [[{
a = 1
<metatable> = {
b = 2
}
}]]))
常见用法:
print(inspect(myobj))