Numpy 将.nrrd文件读入Lua
我有一个.nrrd文件,可以读入python并保存为np数组。我想在lua/torch中使用生成的数组,我该怎么做?或者有没有办法将.nrrd文件直接读入lua?谢谢。就像在评论中一样,应该可以满足您的需求。无论如何,我还发现了一个python库,它看起来更容易实现这一点 您可以通过多种方式将结果导出到Lua中,比如输出到文本文件。我删除了一些有用的URL。正如我所看到的,在Python中使用它非常简单,只需一个Numpy 将.nrrd文件读入Lua,numpy,image-processing,lua,torch,Numpy,Image Processing,Lua,Torch,我有一个.nrrd文件,可以读入python并保存为np数组。我想在lua/torch中使用生成的数组,我该怎么做?或者有没有办法将.nrrd文件直接读入lua?谢谢。就像在评论中一样,应该可以满足您的需求。无论如何,我还发现了一个python库,它看起来更容易实现这一点 您可以通过多种方式将结果导出到Lua中,比如输出到文本文件。我删除了一些有用的URL。正如我所看到的,在Python中使用它非常简单,只需一个import-nrrd和一个frames,options=nrrd.read(“te
import-nrrd
和一个frames,options=nrrd.read(“test.nrrd”)
就像在评论中一样,应该可以满足您的需求。无论如何,我还发现了一个python库,它看起来更容易实现这一点
您可以通过多种方式将结果导出到Lua中,比如输出到文本文件。我删除了一些有用的URL。正如我所看到的,在Python中使用它非常简单,只需一个import-nrrd
和一个frames,options=nrrd.read(“test.nrrd”)
现在您还可以尝试,基本上,您可以使用python中的torch和任何lua库
转换将使用火炬完成。从numpyarray(arr)
,您将得到火炬张量。还有另一个函数tensor.asNumpyArray()
,帮助您转换回numpy数组
import lutorpy as lua
import numpy as np
xn = np.random.randn(100)
## convert the numpy array into torch tensor
tensor_xn = torch.fromNumpyArray(xn)
# you can use torch tensor as well
t = torch.DoubleTensor(10,3)
print(t._size()) # the corresponding lua version is t:size()
## convert torch tensor to numpy array
arr = t.asNumpyArray()
print(arr.shape)
大多数情况下,转换是通过numpy数组和torch tensor之间的共享内存立即完成的,无需保存磁盘,甚至无内存拷贝现在您也可以尝试,基本上,您可以使用python中的torch和任何lua库
转换将使用火炬完成。从numpyarray(arr)
,您将得到火炬张量。还有另一个函数tensor.asNumpyArray()
,帮助您转换回numpy数组
import lutorpy as lua
import numpy as np
xn = np.random.randn(100)
## convert the numpy array into torch tensor
tensor_xn = torch.fromNumpyArray(xn)
# you can use torch tensor as well
t = torch.DoubleTensor(10,3)
print(t._size()) # the corresponding lua version is t:size()
## convert torch tensor to numpy array
arr = t.asNumpyArray()
print(arr.shape)
大多数情况下,转换是通过numpy阵列和torch tensor之间的共享内存立即完成的,没有磁盘保存,甚至没有内存拷贝。