Skip to main content
 首页 » 编程设计

python之对数据集执行快速快速傅立叶变换后的输出数组

2024年10月24日10qq号

我正在尝试对我拥有的数据集执行傅立叶变换,然后分别编写其实部和虚部。

这是我的代码:

import sys,string 
import numpy as np 
from math import * 
import fileinput 
from scipy.fftpack import fft, ifft 
 
temparray = [] 
 
for i in range(200000): 
    line = sys.stdin.readline() ## reads data from a text file 
    fields = map(float,line.split()) 
    temparray.append(fields) 
acf = sum(temparray,[]) ## I need to do this as the appended array from above is nested 
y = np.fft.fft(acf) 
z = (y.real,y.imag) 
print z 

我得到的输出如下:

(array([ 2600.36368107, 2439.50426935, 1617.52631545, ..., 1575.78483016, 1617.52631545, 2439.50426935]), array([ 0. , -767.19967198, -743.75183367, ..., 726.45052092, 743.75183367, 767.19967198])) 

看起来它只打印前几个和最后几个值,完全跳过中间的所有内容。谁能告诉我为什么会这样?

谢谢

请您参考如下方法:

正如其他人所指出的,包括

的修改版本
>>> np.set_printoptions(edgeitems=5,linewidth=80,precision=2,suppress=True,threshold=10)  
>>> a = np.arange(0,100.) 
>>>  
>>> a 
array([  0.,   1.,   2.,   3.,   4., ...,  95.,  96.,  97.,  98.,  99.]) 
>>> np.set_printoptions(edgeitems=5,linewidth=80,precision=2,suppress=True,threshold=100)  
>>> a 
array([  0.,   1.,   2.,   3.,   4.,   5.,   6.,   7.,   8.,   9.,  10.,  11., 
        12.,  13.,  14.,  15.,  16.,  17.,  18.,  19.,  20.,  21.,  22.,  23., 
        24.,  25.,  26.,  27.,  28.,  29.,  30.,  31.,  32.,  33.,  34.,  35., 
        36.,  37.,  38.,  39.,  40.,  41.,  42.,  43.,  44.,  45.,  46.,  47., 
        48.,  49.,  50.,  51.,  52.,  53.,  54.,  55.,  56.,  57.,  58.,  59., 
        60.,  61.,  62.,  63.,  64.,  65.,  66.,  67.,  68.,  69.,  70.,  71., 
        72.,  73.,  74.,  75.,  76.,  77.,  78.,  79.,  80.,  81.,  82.,  83., 
        84.,  85.,  86.,  87.,  88.,  89.,  90.,  91.,  92.,  93.,  94.,  95., 
        96.,  97.,  98.,  99.]) 
 
np.set_printoptions(edgeitems=3,linewidth=80,precision=2,suppress=True,threshold=5) 

也许将阈值设置为某个非常大的数字。

附录

如果我不说明上述问题的最简单解决方案是简单使用,那我就是失职了

>>> list(a) 

你不应该关心一个数组是否在视觉上返回吗?