Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python将数组中的数字从傅里叶变换输出到Excel文件中的一行_Python_Excel_Image Processing_Fft - Fatal编程技术网

如何使用Python将数组中的数字从傅里叶变换输出到Excel文件中的一行

如何使用Python将数组中的数字从傅里叶变换输出到Excel文件中的一行,python,excel,image-processing,fft,Python,Excel,Image Processing,Fft,我想将图像处理的数值结果输出到.xls文件中,精确地在单元格中水平排列,有人能建议使用什么Python模块和添加什么代码吗?换句话说,如何排列数组中的数字,并将它们精确地水平放置在Excel单元格中 Code fragment: def fouriertransform(self): #function for FT computation for filename in glob.iglob ('*.tif'): imgfourier = mahotas.imread (

我想将图像处理的数值结果输出到.xls文件中,精确地在单元格中水平排列,有人能建议使用什么Python模块和添加什么代码吗?换句话说,如何排列数组中的数字,并将它们精确地水平放置在Excel单元格中

Code fragment:
def fouriertransform(self):     #function for FT computation
  for filename in glob.iglob ('*.tif'):
     imgfourier = mahotas.imread (filename) #read the image
     arrayfourier = numpy.array([imgfourier])#make an array 
     # Take the fourier transform of the image.
     F1 = fftpack.fft2(imgfourier)
     # Now shift so that low spatial frequencies are in the center.
     F2 = fftpack.fftshift(F1)
     # the 2D power spectrum is:
     psd2D = np.abs(F2)**2
     print psd2D
     f.write(str(psd2D))#write to file

这应该是一个评论,但我没有足够的代表

别人怎么说

看起来这是的副本,它使用
numpy.savetxt
生成csv文件(excel可以读取)

示例

在我看来,Numpy可能是最简单的方式。你可以得到幻想和模组。在这之后,它将像用逗号分隔每个元素来保存数组一样简单。像这样的东西(经过测试!)更简单

import numpy as np

arr = np.ones((3,3))
np.savetxt("test.csv",arr,delimiter=',',newline=',')
注意,这是一个小问题,因为换行符被视为逗号。这使得“test.csv”看起来像:

1,1,1,1,1,1,1,1,1,1,
那里有9个,我保证!3x3

注意,后面有一个逗号。我能在excel中打开这个没问题,瞧


了解Python的csv模块。您可以编写一个csv文件并在Excel中读取它。谢谢,我添加了以下行:csvout=csv.writer(open(“mydata.csv”,“wb”))csvout.writerows((psd2D)),但是,Excel单元格中的输出不是一行,有没有简单的方法将数组放入.csv文件中的一行中?